Home > Net >  How to have a click button to calculate sum, multiply, modulus in one function only with alert one a
How to have a click button to calculate sum, multiply, modulus in one function only with alert one a

Time:09-28

I have newly started to learn javascript and I have an assignment where I need to have a click button to calculate sum, multiply, modulus within one function only and alert one after the other. So far i was able to only add and multiply differently. If someone can please help in making understand the logic.

JS

var a = Number(prompt("Enter first number"));
    var b = Number(prompt("Enter second number"));
    alert(a   b);  

JS

var a = prompt("Enter first number");
var b = prompt("Enter second number");
var x=parseInt(a);
var y=parseInt(b);

alert(x y);

I tried with both the js above but i'm unable to meet the expectation, if someone could please help

CodePudding user response:

I don't know what you mean,like this?

    function num(a, b) {
           sum = a   b
           mul = a * b
           mod = a / b
       return {sum ,mul ,mod}
   }
   console.log(num(5,6))

CodePudding user response:

i think this might be helpful for you

function calculate(){
 var a = prompt("Enter first number");
 var b = prompt("Enter second number");
 var x=parseInt(a);
 var y=parseInt(b);
 alert("SUM" (x y));
 alert("MUL" (x*y));
 alert("MOD" (x%y));
}
  • Related