Welcome to the Treehouse Community
Looking to learn something new?
Craig Curtis19,985 Points
Why did Mr. Chalkley use Math.floor(Math.random() * sides) + 1 instead of Math.ceil(Math.random * sides) ??
Shouldn't we write less code? Or is he (Mr. Chalkley) just showing the mechanics of Math.random() as being a float between 0 and 1?
Seth Kroger56,403 Points
Math.random() can return 0 and Math.ceil(0) is 0. So the latter code will return a random number from 0 to sides instead of from 1 to sides like the former.
because math floor rounds down and you add the 1 to bring it up to the next integer because you rounded down.