0

Stat point creator help

I am trying to make a script that will create stats for a player based on their input. I want each prompt to display how many stat points they have left. (0-255). The thing is, it calls my inputs strings. How do I turn a string into a number? Do not do the project for me, please just answer my question on turning a string into a number. I want to learn from this. https://code.sololearn.com/WHyfth9gjoer/?ref=app

22nd Nov 2018, 8:18 PM
Yosharu
Yosharu - avatar
4 odpowiedzi
+ 2
Wrap your prompt() call in parseInt( ) or parseFloat( ), depending on what type of number you expect. parseInt(): https://www.geeksforgeeks.org/javascript-parseint-with-examples/ parseFloat(): https://www.geeksforgeeks.org/javascript-parsefloat-with-examples/
22nd Nov 2018, 8:26 PM
Shadow
Shadow - avatar
+ 1
You should enclose the term 250 - healthSelect in braces. The reason for this is that you perform string addition - since prompt() takes in a string as its argument - and the '-' operator is not specified for such a task. However, if you wrap the term in braces, it will be considered as integer subtraction, and afterwards the result will be added to the string before it.
22nd Nov 2018, 8:44 PM
Shadow
Shadow - avatar
0
Shadow It didn’t work. I saved what I did though, do you mind checking it out?
22nd Nov 2018, 8:37 PM
Yosharu
Yosharu - avatar