Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
216,136 Points

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