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
richardforbes
2,384 PointsMy solution for The Random Challenge is different but seems to work.
Will the following:
Math.floor(Math.random() * secondNumber) + firstNumber
produce the same result as:
Math.floor(Math.random()*(secondNumber - firstNumber + 1)) + firstNumber
if used as part of The Random Challenge?
My code is as follows and seems to work:
var firstNumber = parseInt(prompt("Please enter your first number"));
var secondNumber = parseInt(prompt("Please enter your second number"));
var randomNumber = Math.floor(Math.random()*secondNumber)+firstNumber;
document.write("<p>A random number between " + firstNumber + " and " + secondNumber + " is " + randomNumber + "</p>");
1 Answer
Caleb Kleveter
Treehouse Moderator 37,862 PointsIf it works, that's great! It doesn't have to be the same code, it just gotta' work. Although the Mr McFarland uses might be more efficient.