I wanted to display this: Enter your numbers: 1st : 2nd : Answer : I tried doing this:

var a = prompt("A : ", "");
var b = prompt("B : ", "");
function calc(a,b)
{
   return a + b;
}
alert ("The addition is =" + calc(a,b);
2

There are 2 answers

3
stahlmanDesign On BEST ANSWER

To do it with only one prompt:

var numbers = prompt("Enter two numbers separated by a semi-colon: ", "");
var a = numbers.split(";")[0];
var b = numbers.split(";")[1];

function calc(a,b)
{
   return parseFloat(a) + parseFloat(b);
}
alert ("The addition of " + numbers + " is = " + calc(a,b));
1
depperm On

You just need to parse the return from the prompts

var a = prompt("A : ", "");
var b = prompt("B : ", "");
function calc(a,b)
{
   return parseFloat(a) + parseFloat(b);
}
alert ("The addition is =" + calc(a,b));