+ 1

Javascript Math Operator not working!!

Heres my code: var minute = prompt("Minutes : ", "0"); var second = prompt("Seconds : ", "0"); var convert = minute * 60 var wait = convert + second document.write(wait) If you enter 5 min and 30 sec, it displays 30030 instead of 330. Please help!

9th Jun 2017, 4:49 PM
BGMead
BGMead - avatar
3 Answers
+ 4
Try this: var minute = Number (prompt("Minutes : ", "0")); var second = Number (prompt("Seconds : ", "0"));
9th Jun 2017, 4:53 PM
CalviÕ²
CalviÕ² - avatar
+ 1
Worked. Thanks!
9th Jun 2017, 4:55 PM
BGMead
BGMead - avatar
+ 1
js provide a lot of type convert. If you use something like that also will work: convert/1+second/1 +convert++second it happens because prompt returns string. and if you concatenate two strings "300" and "30" it will be string "30030"
9th Jun 2017, 6:51 PM
ŠŠ»ŠµŠŗсŠ°Š½Š“р Š”Š¾Š»Ń
ŠŠ»ŠµŠŗсŠ°Š½Š“р Š”Š¾Š»Ń - avatar