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) Working With Numbers The Random Challenge

Angel Manuel Couso Jimenez
PLUS
Angel Manuel Couso Jimenez
Courses Plus Student 4,402 Points

my 2nd part of the challenge, Please give me some feedback

//Sorry for my English if i write something Wrong

// Presentation --------------
alert ('This is my Random Challenge. Ready???');
alert ('Let\'s do it!!');

//Ask for the lower limit ---------------
var lowerLimit = parseInt(prompt("Give me the lower limit of our range"));

//Ask for the Higher limit ---------------

var higherLimit = parseInt(prompt("Give me the higher limit of our range"));


//Doing some calculations ---------------

// getting a random number between 0 and the 
//diference of both limits, and then adding 
//that random to the lowest limit, we get a 
//random number between or both limits

// diference between both limits
var range = higherLimit - lowerLimit;

//Getting random number in the range
var randomNumber = Math.floor(Math.random() * range);


//printing the lower limit plus the random between our range
document.write(randomNumber + lowerLimit);

1 Answer

Olga DC
Olga DC
16,680 Points

Hi Angel. I think with that code, the upper limit number can never be the output. The range should be higherLimit - lowerLimit + 1, that is:

var range = higherLimit - lowerLimit + 1;

Also you have to check whether the user provided valid input, and if he didn't, then show a message that he must enter a number.

Angel Manuel Couso Jimenez
Angel Manuel Couso Jimenez
Courses Plus Student 4,402 Points

Thanks Olga i missed that +1, thanks, and now im learning about conditions so in that challenge i wasnt able to validate the answer from the user, but im now, very very thanks to u