JavaScript JavaScript Numbers The Math Object Random Number Challenge – Solution

Caroline Louw
Caroline Louw
12,155 Points

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

Steve Fau
Steve Fau
5,621 Points

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

With the parseInt() method.

Georgia Lloyd
Georgia Lloyd
784 Points

Thanks, I was also wondering this