Turning the input into a number | Sololearn: Learn to code for FREE!
+ 1

Turning the input into a number

How can i turn the input wrote in prompt() in javascript into a number because when i try to sum to numbers wrote in prompt() they are counted as strings In Python there is a way and it looks like this. float(input("write a number")) this turns the input into a float number

10th Feb 2019, 8:41 PM
Mario
Mario - avatar
3 Answers
+ 1
You can use Number (yourVar) where yourVar is the name of the variable. For example var num = Number(yourVar).
10th Feb 2019, 10:21 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
0
TheWhiteCat💡 thanks That worked
11th Feb 2019, 12:47 PM
Mario
Mario - avatar
0
You are welcome, Mario.
11th Feb 2019, 4:09 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar