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

Kandance Ferguson
Kandance Ferguson
6,271 Points

Completing the Random Number Challenge Part II - Trouble getting error code to run

I can run the code, up until the error should display. For some reason, the error doesn't display. Any suggestions?

function randomNumber(num1, num2) {
    if ( isNaN(num1) || isNaN(num2) ) {
      throw new Error('Both arguments must be numbers');
    }
    return Math.floor(Math.random() * (num2 - num1 + 1)) + num1;
}

console.log( randomNumber(18, 24) );
console.log( randomNumber(100, 500) );
console.log( randomNumber('ten', 10) );
console.log( randomNumber(15, 37) );

3 Answers

LaVaughn Haynes
LaVaughn Haynes
12,397 Points

The only way that I could repeat your issue was to disable JavaScript error output in the console. Can you verify that yours is enabled?

JavaScript output

LaVaughn Haynes
LaVaughn Haynes
12,397 Points

?? I tried the code in Chrome, Firefox, and a Workspace and I always get the error displayed in the console as it should. I'm not sure why it wouldn't display for you. Do you get the first two random numbers and then nothing?

Kandance Ferguson
Kandance Ferguson
6,271 Points

Yep, first two numbers, then nothing. I'm also using Firefox.