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 trialAlanis Chua
2,830 PointsReferenceError: 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?
3 Answers
Alfi Potter
7,248 PointsFunctions 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)
Alanis Chua
2,830 Pointsthanks!
nelson taj
Courses Plus Student 3,869 PointsHere 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
6,908 PointsI had the same problem. Thanks!
Danny Percy
3,719 PointsDanny Percy
3,719 PointsAnd also make sure you delete that semicolon at the end of function :) Have a nice day!