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 trialCaroline Louw
12,155 PointsHow does the program know that the highNumber variable is a number and execute the first if statement?
And if not the else statement is executed?
4 Answers
Steve Fau
5,622 PointsHey Caloline,
This got me for a sec too, but here's the solution:
Before he goes to the if statement, he's parsing the number from the user input via the parseInt() method.
The user either enters something that can be parsed into a number, or the parseInt() method returns NaN, which then evaluates to false.
Read more about why NaN evaluates to false and other falsy values here: https://developer.mozilla.org/en-US/docs/Glossary/Falsy
Diego Alvarez
6,680 PointsWith the parseInt()
method.
Caroline Louw
12,155 Pointsthanks
Skyler Harris
7,670 PointsNice answer Steve that made a lot of sense!
Georgia Lloyd
3,384 PointsThanks, I was also wondering this
Md. Syful Islam
9,463 PointsMd. Syful Islam
9,463 PointsThanks Steve!
Caroline Louw
12,155 PointsCaroline Louw
12,155 Pointsthanks