JavaScript JavaScript Basics Creating Reusable Code with Functions Random Number Challenge, Part II Solution

Reza Zandi
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
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.

Steven Parker
Steven Parker
174,085 Points

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