+ 3

How can I add math to my JavaScript prompt() function?

Coding please

17th May 2017, 7:00 AM
Iwan
Iwan - avatar
5 ответов
+ 4
Example please.
17th May 2017, 7:25 AM
Tim G
Tim G - avatar
+ 4
var y = 5 var x = prompt(Enter a number:); var z = alert("The answer is: " x * y);
17th May 2017, 7:27 AM
Iwan
Iwan - avatar
17th May 2017, 7:30 AM
Iwan
Iwan - avatar
+ 4
@Iwan de Jong. It will not work with + or - . I still suggest to use the Number function to convert the prompt string to a number before calcuating with it. var x = Number(prompt("Enter a number:"));
17th May 2017, 7:36 AM
Tim G
Tim G - avatar
+ 2
var y = 5 do var x = prompt("Enter a number:"); while (isNaN(x)); alert("The multiply is: " + x * y); alert ("The sum is: " + Number(x) + y);
17th May 2017, 8:46 AM
Calviղ
Calviղ - avatar