prompt() in JS gives you string, how to have number? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

prompt() in JS gives you string, how to have number?

When I use prompt() in JavaScript, I receive a string variable. What do I do so that prompt() gives a number variable, or is there another way besides prompt() ?

16th Jan 2018, 10:27 AM
Nytro007
Nytro007 - avatar
6 Answers
+ 4
For example, var a=prompt(); alert(parseInt(a)+1);
16th Jan 2018, 10:33 AM
Petr Leliaev
Petr Leliaev - avatar
+ 4
tq
16th Jan 2018, 10:39 AM
Nytro007
Nytro007 - avatar
+ 4
Be careful, in some situations it returns null.
28th Jan 2018, 8:23 AM
Vladislav Tikhiy (SILENT)
Vladislav Tikhiy (SILENT) - avatar
+ 3
@Petr Show me how to use it pls
16th Jan 2018, 10:30 AM
Nytro007
Nytro007 - avatar
12th Jul 2019, 11:51 AM
arieh
0
parseInt(string) is integer in JavaScript.
16th Jan 2018, 10:29 AM
Petr Leliaev
Petr Leliaev - avatar