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

Another solution

Hello (again)

Sorry, but since the teacher gave a solution by using another method, I would like to check if my response would be correct or not. Thank you!! :))))

let getRandomNumber = (upper, lower) => {
  if ( parseInt(upper) && parseInt(lower) ) {
      const randomNumber = (Math.floor(Math.random() * (upper - lower + 1)) + lower) 
      return randomNumber
  } else console.log(`You have to insert two numbers`)  

};

1 Answer

Steven Parker
Steven Parker
231,261 Points

This function would behave differently from the video example. The "throw" in the video aborts the entire program; but if an error occurs here, the function will long a message, but finish normally yet without returning anything.

Also, using a logic operator on two numbers is not a reliable way to detect if the values are not numbers. For example: try calling the function to get a random number between 0 and 9.