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

Neil Bircumshaw
seal-mask
.a{fill-rule:evenodd;}techdegree
Neil Bircumshaw
Full Stack JavaScript Techdegree Student 14,597 Points

Don't quite understand the last part of the problem.

So I understand everything except this part...Math.floor(Math.random() * (topNumber - bottomNumber + 1)) + bottomNumber;

I'm unsure why one variable is being subtracted from another. I understand you put +1 because of the Math.floor needs that, but then why do you then add the bottomNumber variable again.

Cheers guys, sorry if it sounds like a silly question :)

Neil Bircumshaw
seal-mask
.a{fill-rule:evenodd;}techdegree
Neil Bircumshaw
Full Stack JavaScript Techdegree Student 14,597 Points

Perfect! It's clicked, I had to get my pen and paper out to make sense of it after then reading one of the very good answers on there. Don't think it was explained in good detail at all in the video. I would say this needs re-doing to be explained more thoroughly, it was kind of just throw at you, expecting you to know what was going on.

Thank you so much for your post my friend :)

1 Answer

changed from comment to answer