Welcome to the Treehouse Community
Looking to learn something new?
Adam Maley5,946 Points
Using Math.Ceil instead of Math.floor?
Math.floor(Math.random() * 6) + 1 How would this ever result in 0 like he said ?
the + 1 at the end would stop this from happening?
Tina Gee3,296 Points
If you test Math.ceil() and Math.floor() in the console, it'll make a bit more sense.
For example, Math.ceil(-0.001) returns -0. Math.floor(-0.001) returns -1.
Since we are working with rolling dice and dice have sides 1 through 6 but never a 0 side, we will want to use Math.floor() because it will prevent us from having to deal with the possibility of Math.ceil returning a 0.
Steven Parker221,204 Points
It might result in 0 before the 1 was added.
Using Math.Ceil would not help the case where the value was actually zero.
I believe the possibility of the result of the formula being 0 was discussed as the reason to add 1 to it. If you heard otherwise, can you give a specific time reference in the video for where it is said?