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 Solution

Alanis Chua
Alanis Chua
2,830 Points

ReferenceError: isNan is not defined

function randomNumber(lowerValue, upperValue){
  if( isNan(lowerValue) || isNaN(upperValue) ){
    throw new Error('error message');
} 
  return Math.floor(Math.random() * (upperValue - lowerValue + 1)) + lowerValue; 
};

console.log( randomNumber(2,33) );
console.log( randomNumber(2,"aa") );

why is there an error on second line?

Danny Percy
Danny Percy
3,719 Points

And also make sure you delete that semicolon at the end of function :) Have a nice day!

3 Answers

Functions in Javascript are case sensitive, so isNan fails as the function is not defined whereas isNaN succeeds.

So like you did for the upperValue isNaN(upperValue) should be the same for isNaN(lowerValue)

nelson taj
PLUS
nelson taj
Courses Plus Student 3,869 Points

Here is the correct code below. You typed an small 'n' in the second line. good luck! N

function randomNumber(lowerValue, upperValue){ if( isNaN(lowerValue) || isNaN(upperValue) ){ throw new Error('error message'); }

Janet Leon
Janet Leon
6,908 Points

I had the same problem. Thanks!