Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.Start your free trial
Forrest Pollard1,988 Points
Cannot seem to correctly change the value of a variable from a prompt
Was experimenting with what i learned from this lesson by trying to do something myself but I am struggling. here is my code, i think you will understand what I have been trying to do,
var score = 0;
score += 10, score +=5;
var bonusPoints = 0;
bonusPoints += prompt("input desired bonus points");
score += bonusPoints;
however it keeps adding whatever is input in the prompt as a string at the end of the score value. Any help is greatly appreciated, many thanks :)
Austin Whipple29,725 Points
By default, the value submitted to the prompt you're displaying is going to be stored as a string. Using
parseint() without much problem, but perhaps
Number() would work as well. Here's a StackOverflow article with lots more information.