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!
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
Nikita Tsigelberg2,625 Points
Is 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;
Steven Parker228,026 Points
The "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.