+ 3
How can I add math to my JavaScript prompt() function?
Coding please
5 Answers
+ 4
Example please.
+ 4
var y = 5
var x = prompt(Enter a number:);
var z = alert("The answer is: " x * y);
+ 4
No worries,
https://code.sololearn.com/W20oXs4SUbZz/?ref=app
+ 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:"));
+ 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);