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 trialStaclin Patterson
4,589 PointsQuiz challenge
I did a simple math quiz to make it easy to test. It looked something like this.
var score = 0; var questionOne= prompt('What is 1*0?'); if (questionOne === 0){score +=1}
When I did this the score would not add one when I gave the correct answer. After looking through the forms I changed the conditional statement to: if(questionOne >=0){score +=1}. After doing so my program worked and would add 1 to the score variable after a correct answer was giving.
I'm just wondering why the less than symbol is necessary rather than the equal to operator?
1 Answer
Steven Parker
231,271 PointsThe inequality part of the operator was incidental. The real issue was that the original test was using the "strict" equality comparison ("===") which only matches when the terms are the same type. But the results from "prompt" are a string which was being compared to a number, so that operator would never consider them the same.
The normal equality operator ("=="), and in this case the greater-or-equal operator (">=") do automatic type conversion as needed.