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 trialWuen Han Lee
Courses Plus Student 2,305 PointsMath.floor(Math.random() * 256 We wont be getting 256 with this line, will we?
since 1 is exclusive from Math.random(). Are we eliminating the possibility of getting 256?
2 Answers
Bryan Laraway
13,366 PointsYes, that's correct. Math.random() doesn't include 1, so we wouldn't get 256.
babasariffodeen
6,475 PointsHi Wuen Han Lee,
You are right. We won't get 256. There are two reasons for this:
1) As Bryan Laraway stated already, Math.random() does not include 1
2) The Math.floor() function will round down a number to the lower integer. For example, let's take the number 1.6 so Math.floor(1.6) = 1. So since this function doesn't round up but only down, that's another reason we won't 'reach' 256.
Hope that helps.
kavumo mfinanga
17,182 Pointskavumo mfinanga
17,182 PointsYes, But if you want to get 256, That means 255 will be your maximum random number generated which is the highest decimal value for color (255)