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 trialNikita Tsigelberg
2,625 PointsIs this way a good way to write the code?
I did it a bit differently and it works, is the way i did it suitable?
var firstNum = prompt("Pick a random number");
var secondNum = prompt("Pick a second number");
firstNum = parseInt(firstNum);
secondNum = parseInt(secondNum);
var final = Math.floor(Math.random(firstNum) * secondNum) + 1;
var message = final + " is a number between " + firstNum + " and " + secondNum;
document.write(message);
Nikita Tsigelberg
2,625 Pointsi updated the question.
1 Answer
Steven Parker
231,271 PointsThe "random" method does not use an argument, so passing the first number to it will not have any effect on the output.
Also, the formula for generating a number between two limits is a very specific well-known standard. Deviating from it will almost certainly produce something other than the intended results.
varlevi
8,113 Pointsvarlevi
8,113 PointsThe link leads to a page not found error! Please fix so we can give you feedback!