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 Numbers The Math Object Random Number Challenge – Solution

Random Number Challenge Part II- My Solution

// Collect input from a user
let userLow = prompt("Enter a low number into the text box bellow.");
let userHigh = prompt("Enter a high number into the text box bellow.");


// Convert the input (as a string) to a number
userLow = parseInt(userLow);
userHigh = parseInt(userHigh);


//conditional if user enters both required numbers
if (userHigh && userLow){
  const randomNumber = Math.floor(Math.random(userLow)* userHigh)+1;

  console.log(`The random number generated from ${userLow} to    ${userHigh} is ${randomNumber}.`) 

//if user does not enter required numbers  
} else {
  console.log('Number is needed to calculate. Reload page and try again.');
}

Nice. This helps!

T. Gontarek I tested your solution and if you do low number 2 and high number 4 you can get a 1 as a result.

boi
boi
14,242 Points

This solution needs a solution.

1 Answer

OOPS! I know I spelled below incorrectly.