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

Raul Cisneros
Raul Cisneros
7,319 Points

Not sure if I understood the challenge, but here is my take on it.

//random number 1

var userNumOne = prompt("Please type a random number");// user data entry 1 console.log(userNumOne);// code test var userRandomNum = Math.floor(Math.random() * parseInt(userNumOne) + 1);// random number creation console.log(userRandomNum);// code test

//random number 2

var userNumTwo = prompt("Please type another random number");// user data entry 2 var doubleTrouble = Math.floor(Math.random() * (parseInt(userNumTwo) + userRandomNum) + 1); console.log(userNumTwo); console.log(doubleTrouble); alert("Here is your random number x2... " + doubleTrouble + ".");

1 Answer

I think you're misunderstanding the question. The ultimate goal of the program is to allow the user to input two values and then have the browser generate a random number between those two values. Here was my answer:

var num1;
var num2;
var rand;
var limit;

num1 = parseInt(prompt("Please Enter your first number: "));
num2 = parseInt(prompt("Please Enter your second number: "));
limit = (num2 - num1)/2;
rand = Math.abs(Math.round(Math.random() * (num2 - num1)) + num1);


alert("Your random number between " + num1 + " and " + num2 + " is " + rand + "!");