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

Reza Zandi
seal-mask
.a{fill-rule:evenodd;}techdegree
Reza Zandi
Full Stack JavaScript Techdegree Student 1,599 Points

Posting my code

I was having trouble with getting the error message to spit out my custom message, then I realized I had a lower-case e rather than a capital E in Error. In python, if I did that, it would show a distinct difference, but both times, the color of 'error' and 'Error' in the workspace was the same. Is that because of JS or because of the workspace- text editor? If I was using Sublime, would it show me a color difference between error and Error? Given assuming one is a keyword and the other isn't?

function getRandomNumber( lower, upper ) {
  if( isNaN(lower) || isNaN(upper)){
    throw new Error("Strings are not allowed in this program. Please refresh and type only numerical numbers.");
  }
  else {
    return Math.floor(Math.random() * (upper - lower + 1)) + lower; 
  }
}

document.write( getRandomNumber( 9, 24),'<br/>' );

document.write( getRandomNumber( 1, 100 ),'<br/>' );

document.write(getRandomNumber( 200, 500 ),'<br/>');

document.write( getRandomNumber( 1000, 20000 ),'<br/>' );

document.write( getRandomNumber( 'nine', 100 ));
Reza Zandi
seal-mask
.a{fill-rule:evenodd;}techdegree
Reza Zandi
Full Stack JavaScript Techdegree Student 1,599 Points

I just tried it in sublime and it does. Need to upgrade the text editor cuz that on issue boggled my mind for like 20 min. I will use sublime from now.

1 Answer

Steven Parker
Steven Parker
231,110 Points

You can make suggestions directly to the staff as described on the Support page.