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! While you're at it, check out some resources Treehouse students have shared here.
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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Forrest Pollard](https://secure.gravatar.com/avatar/29a2caeca2d09e5bb46cb1c55f3d02c3?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Forrest Pollard
1,988 PointsCannot 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;
alert(score);
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 :)
1 Answer
![Austin Whipple](https://secure.gravatar.com/avatar/197cbf097a85c0eb7a8ae467c6f9e67c?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Austin Whipple
29,725 PointsHi Forrest,
By default, the value submitted to the prompt you're displaying is going to be stored as a string. Using +=
is going to produce strange results using anything that's not an integer. Luckily, JavaScript has some handy functions to convert strings to integers/numbers! I suspect you can use parseint()
without much problem, but perhaps Number()
would work as well. Here's a StackOverflow article with lots more information.