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 Functions Arrow Functions Testing for Number Arguments

Not recieving an error regardless of what arguments get passed

Have the code set up exactly the same and yet my or statement doesn't seem to be getting engaged.

function getRandom(lower, upper = 100) { if (isNaN(lower) || isNaN(upper) ) { throw Error("both arguments must be numbers"); } return Math.floor(Math.random() * (upper - lower + 1)) + lower;

} // Call the function and pass it different values

console.log(getRandom(1, 10)); console.log(getRandom(1000, 1000000));

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Zach Hope! In both your calls to the function you are sending in numbers. The only way this will throw an error is if one or more are not numbers. When I run this, the error is thrown as expected.

console.log(getRandom("tree", "house"));

Hope this helps! :sparkles:

In the console I was adding paran around one of the numbers thinking it would make the number a string yes was unable to manifest the error though still not sure what’s going on with it