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
charles bempah
1,295 Pointshttps://w.trhou.se/lqy4i6u7c6 I can't see the error message won't appear in the console. Any hints please?
I can't see the error message won't appear in the console. Any hints please?
2 Answers
rydavim
18,814 PointsOkay, so you've got the right idea. Your biggest issue is the order you have your code in.
function getRandomNumber( lower, upper ) {
// This is a return statement, so you're exiting the function immediately.
return Math.floor(Math.random() * (upper - lower + 1) + lower);
// This code will never run. You've already returned above and exited back out of the function.
if (lower == isNaN || upper == isNaN) { // isNaN() is a function that returns a boolean. See comment below.
throw new Error('Please type a number');
}
else getRandomNumber(); // You're trying to call your function again, but with no arguments?
}
isNaN already returns a Boolean value, no need to compare it to anything. Instead of using the == operator, you should call it directly on your variable. isNaN(lower), for example. For more information, take a look at the MDN page.
Once you've got that syntax in, try reordering your code to do the NaN test first. Once you've tested your variables to make sure they're numbers, then do the return statement.
Hopefully that helps point you in the right direction, but if you still find yourself stuck let me know and we can walk through a solution. Happy coding!
charles bempah
1,295 PointsThanks a lot
varlevi
8,113 Pointsvarlevi
8,113 PointsWhat lesson are you working on right now? If we can watch the video, that might help.