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 Basics (Retired) Creating Reusable Code with Functions Random Number Challenge, Part II

Luqman Shah
Luqman Shah
3,016 Points

Is this how he wants us to use the if conditional in this challenge?

I would like to know if this is correct, before I proceed coding and moving on to the solution video.

console.log( getRandomNumber( 'nine', 24 ) );
if ( isNaN('nine') || isNaN(24) ) {
  throw new Error('error! not a number');
}

2 Answers

Luqman Shah
Luqman Shah
3,016 Points

Thanks, I watched the solution video, I got it now :) And congratulations on graduating the FEWD techdegree!!! I was wondering why your profile image had that green border lol.

jeffrey bachynski
jeffrey bachynski
5,179 Points

I think he is asking you to test the arguments being passed into the getRandomNumber(lower, upper) function so that it can test the values being passed to it when running the console.log(getRandomNumber(argument1, argument2)); statements.

The reason why you would want to test a function like this is because if the function does not receive two numbers as arguments, it can't generate a random number with the argument values that the getRandomNumber() function received.

So, you should place your "if statement" inside the the getRandomNumber() function, where it is created, inside it's curly braces, but before the return statement, and pass the lower and upper variables from the getRandomNumber() declaration above into the isNaN() test. eg. isNan(lower)

That way when you run the function, if one of the values being passed as an argument is not a number, it will display the custom error message that you created indicating why the error occurred.

So when you run

console.log( getRandomNumber( 'nine', 24 ) );

it would show

"Uncaught Error: error! not a number"