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) Creating Reusable Code with Functions Random Number Challenge

Anthony gedeon
Anthony gedeon
6,140 Points

It works but is this the right way of doing it?

It is within the range of arguments but am I cheating the system by omitting the formula?

function minMax(start, end){ var randomChose = Math.floor(Math.random() * end) + start; return randomChose; }

console.log(minMax(0, 4) );

1 Answer

Steven Parker
Steven Parker
231,275 Points

You haven't omitted the formula, but you've created a different one. It may seem to perform similarly for some arguments, but the difference will become obvious with others.

For example, try using this function to generate a random number between 80 and 90.