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

Here is my code , is there any easy solution ? , is it the proper way?

var number = prompt ("tell me your number");
number = parseInt(number);
number = Math.floor(Math.random() * number)+1;
alert(number); 

1 Answer

Hey Arun,

Input you receive from the user is always a String, so you'll want to store that input into a new variable when casting it into an integer.

Seeing as this is the Random Challenge, your final mark-up should look similar to this:

var inputOne = prompt('Please type your first integer');
var bottomNumber = parseInt(inputOne);
var inputTwo = prompt('Please enter your second integer');
var topNumber = parseInt(inputTwo);
var diceRoll = Math.floor(Math.random() * (topNumber - bottomNumber + 1)) + bottomNumber;
var message = "<p>" + diceRoll + " is a number between " + bottomNumber + " and " + topNumber + ".</p>";
document.write(message);

Did you Run my Code ? it works :)