Explain Math.floor(Math.random()*2)


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
What value does this code assign to the youHit?
Why do we multiply Math.random()*2 ?

<In what way does your code behave incorrectly? Include ALL error messages.>

``` var youHit = Math.floor(Math.random()*2); ```

#2

Math.random generates a random number between 0 and 1. If you now multiply this number by two, all numbers generated below 0.5 are less then 1 (after being multiplied). everything above 0.5 is now bigger then 1. Then you floor the number (throw away everything after the decimal), which means you have two possible numbers: 0 and 1

Or, true (1) and false (0), so this is used to give the user a 50% to hit