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

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 + "!");