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 trialJonathan Ng
7,982 PointsparseInt() not working with prompt()
Hi, I can't seem to get the second question to work properly and increment the score by 1. I suspect the parseInt() method is not working properly, but I can't figure out why. Thanks.
var correct = 0;
var questionOne = prompt("What is the largest country in the world?"); if (questionOne.toLowerCase() === "russia") { correct++; }
var questionTwo = prompt("What is 10% of 5?"); if (parseInt(questionTwo) === 0.5 || parseInt(questionTwo) === .5) { correct++; }
alert(correct);
1 Answer
Osaro Igbinovia
Full Stack JavaScript Techdegree Student 15,928 PointsHi Jonathan, the parseInt() method is used to extract integers from a string(which is anything between quote marks). Looking at your code you're trying to extract '0.5' which isn't an integer, it's a floating point number(decimal number). So you're to use the parseFloat() method instead. Happy coding :)