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

Matthew Cannaverde
Matthew Cannaverde
4,588 Points

I am also getting the "isNAN is not defined" error.

function getrandomNumber(x, y) {
  if (isNAN(x) || isNAN(y)) {
        throw new Error("This function only takes numbers and not strings");
      } else {
      if (x>y) {
        var randomNumber = Math.floor(Math.random() * (x-y)+ 1) + y; 
  }
      else {
        var randomNumber = Math.floor(Math.random() * (y-x)+ 1) + x; 
  }
  return randomNumber
}}

console.log(getrandomNumber("five", 10));
console.log(getrandomNumber(10, 5));
console.log(getrandomNumber(6, 500));
console.log(getrandomNumber(40, 900));

Not sure why I am getting the error. I decided to attempt this challenge with the idea that the function could determine the smaller and larger number. I haven't had a ton of practice nesting conditional statements.

Mindy Gerecke
Mindy Gerecke
2,817 Points

I had that same issue! I cannot believe it all came down to a typo! :(

2 Answers

William Li
PLUS
William Li
Courses Plus Student 26,868 Points

Hi, Matthew, it's a misspelling error. isNaN, not isNAN.

Matthew Cannaverde
Matthew Cannaverde
4,588 Points

Wow... Thanks William for clearing that up. For some reason I kept overlooking that. Too little coffee or something like that. Thanks again!