 Introduction to JavaScrip > (3) Learn JavaScript Functions > Project = “Rock, Paper, or Scissors”

Math.floor(Math.random() *3);

The video that explains the solution to this project explains that Math.random generates a number between 0 and 1. Multiplying that random output by 3 generates a number greater than 1.

I do not believe this is a true statement because, for an example, 0.02 is a number between 0 and 1. When I multiply 0.02 by 3 the answer is 0.06. That output 0.06 is less than 1.

I’m so confused by this logic help clarify please?

1 Like

the possible values are: 0, 1 and 2. Which is also how its mentioned in the instructions and the hint

2 Likes

`Math.floor()` will take the result of `Math.random()*3`, and ‘round’ it down to an integer. That will result in either 0, 1 or 2. For example:
.02 * 3 = .06 => Math.floor(.06) => 0
.52 * 3 = 1.56 => Math.floor(1.56) => 1
.87 * 3 = 2.61 => Math.floor(2.61) => 2
So, `Math.floor(Math.random() *3)` will give 3 possible results: 0-2. If the 3 were changed to 8, you’d have 8 possible results: 0-7. Hope this helps!

1 Like