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 trialArun B.S
6,239 PointsHere 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
jacobproffer
24,604 PointsHey 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);
Arun B.S
6,239 PointsArun B.S
6,239 PointsDid you Run my Code ? it works :)