0

Umm why isn't this working

I'm trying to make a multiplication calculator but its not working can you tell me why? var n = prompt("Enter a number", ""); var multiply; var answer = Math.multiply(n); alert("The answer " + n + " is " + answer);

8th Aug 2018, 4:30 PM
SarahDiamondFox
SarahDiamondFox - avatar
6 Answers
+ 4
Assuming it's JavaScript, n is a string. Multiply requires 2 or more arguments and can't process strings. Try this: var n = parseInt(prompt("Enter a number", "")); var answer = math.multiply(n, n); alert("The answer " + n + " is " + answer);
8th Aug 2018, 4:58 PM
John Wells
John Wells - avatar
+ 2
math.js that defines multiply needs to be include as it isn't a standard part of JavaScript. Personally, I'd just do n*n or whatever you're looking for.
9th Aug 2018, 1:45 AM
John Wells
John Wells - avatar
+ 1
Okay thank you.
9th Aug 2018, 1:46 AM
SarahDiamondFox
SarahDiamondFox - avatar
+ 1
yay! it works now
9th Aug 2018, 1:48 AM
SarahDiamondFox
SarahDiamondFox - avatar
0
yea it's java script I guess I left that out
9th Aug 2018, 1:40 AM
SarahDiamondFox
SarahDiamondFox - avatar
0
but I keep getting the multiply is not a function error
9th Aug 2018, 1:42 AM
SarahDiamondFox
SarahDiamondFox - avatar