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

JavaScript JavaScript Basics (Retired) Working With Numbers The Random Challenge Solution

Nikita Tsigelberg
Nikita Tsigelberg
2,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;

document.write(message);

varlevi
varlevi
8,113 Points

The link leads to a page not found error! Please fix so we can give you feedback!

1 Answer

Steven Parker
Steven Parker
231,275 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.