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 trialAngel Manuel Couso Jimenez
Courses Plus Student 4,402 PointsMy solution, Is Correct?
function getRandomNumber( lower, upper ) {
if (isNaN(lower) || isNaN(upper)) {
throw new Error('At least one of the parameters given isnt a numbers');
} else {
return Math.floor(Math.random() * (upper - lower + 1)) + lower;
}
}
console.log( getRandomNumber( 'nine', 24 ) );
console.log( getRandomNumber( 1, 100 ) );
console.log( getRandomNumber( 200, 'five hundred' ) );
console.log( getRandomNumber( 1000, 20000 ) );
console.log( getRandomNumber( 50, 100 ) );
2 Answers
Steven Parker
231,271 PointsIt looks like you got it. Good job!
Daniel Salvatori
2,658 Pointsi had almost the same but I wrote the isNan part like this
if(isNaN(lower) == true || isNaN(upper) == true){
I suppose it is unnecessary but can I write it this way?
Steven Parker
231,271 PointsYou can, but it's never necessary to compare a booean value to "true". Just naming it does the same job.
Angel Manuel Couso Jimenez
Courses Plus Student 4,402 PointsIsNaN return a Boolean answer so like said Steven compare a Boolean answer with "true" or "false" is kind of redundant, but redundant don't means u can't do it Sorry if I write something wrong am still learning English :)