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

JavaScript JavaScript Numbers The Math Object Random Number Challenge – Solution

How 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

Hey 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

thanks

With the parseInt() method.

thanks

Skyler Harris
Skyler Harris
7,670 Points

Nice answer Steve that made a lot of sense!

Georgia Lloyd
Georgia Lloyd
3,384 Points

Thanks, I was also wondering this