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 Solution

what if we do it like this?

i was wondering if this would be a good practice since it seems to get the same results.

function getRandomNumber(upper, lower) {

   return Math.floor(Math.random() * upper) + lower;

}

getRandomNumber(6, 1);

any help will be appreciate.. thanks

1 Answer

Steven Parker
Steven Parker
231,236 Points

That works just fine in this particular situation, but only because "lower" is being set to 1.

To make the formula more generic, it needs to compute the range with the method shown in the video.

thank you so much for you help Steven