+ 5

I would like to know how I turn a string into an integer in JavaScript.

I'm coding a game with web languages, but I need to track the score and hits dealt.

31st Oct 2018, 12:36 PM
Michele Rene Machado
Michele Rene Machado - avatar
6 Answers
+ 8
Hi Michele Rene Machado ! You can use the parseInt() function. parseInt("12") would become the integer 12.
31st Oct 2018, 12:43 PM
Kishalaya Saha
Kishalaya Saha - avatar
+ 4
Oh, okay, thank you, I wasn't aware of the function.
31st Oct 2018, 2:16 PM
Michele Rene Machado
Michele Rene Machado - avatar
+ 4
You're most welcome! Have fun building your game! 😊
31st Oct 2018, 2:33 PM
Kishalaya Saha
Kishalaya Saha - avatar
+ 2
Michele Rene Machado the asker can mark best answer (the tick below upvote/downvote)
31st Oct 2018, 4:43 PM
Gordon
Gordon - avatar
+ 2
A quicker method is to simply multiply it by one. "12"*1 === 12
13th Jan 2019, 3:28 PM
Valtrius Malleus
Valtrius Malleus - avatar
0
This can also be achieved using the Number() method however parseInt() is preferred
1st Nov 2018, 5:51 PM
Brandon
Brandon - avatar