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 trialJamilur Rahman
3,336 PointsMy Code works really well. Can someone check out my code to see why it is so different the video solution?
var input = prompt('What is the first number'); var input1 = prompt('What is the end number');
var firstNum = parseInt(input); var endNum = parseInt(input1);
var roll = Math.floor((Math.random()*endNum) + firstNum ); var message = "<p>" + roll + " is a number between " + firstNum+ " and " + endNum + ".</p>"; document.write(message);
alert(roll);
Jamilur Rahman
3,336 PointsIt is not really a question. It is a coding challenge for java script. they want me to ask for first num and second num. then make it into a range. i just wanted to know if it elogic for my var roll is correct
1 Answer
Steven Parker
231,248 PointsThe formula shown here is likely to generate a number well outside the requested range. For example, try asking it for a number between 1000 and 1010.
The classic formula (adapted to these variable names) would be:
ā Math.floor((Math.random() * (endNum - firstNum + 1)) + firstNum;
Fernando Boza
25,384 PointsFernando Boza
25,384 PointsHi there, what video are you referring to ? be sure to create questions from video lessons page.