JavaScript Treehouse Club - MASH MASH - JavaScript MASH Choice and Random Number Functions

is Math.random an already existing function in Javascript or is it newly defined by Joy..

is Math.random an already existing function in Javascript or is it newly defined by Joy.. I dont understand why we are using this random number. and why a number between 0 and 1. Why we multiply it ?

3 Answers

The Math.random function is built-in to JavaScript, so there's no need for Joy to pre-define it. Also, the Math.random function is useful for making random numbers. Math.random() Just returns a value from 0 to 1, including decimals. Let's say when we run the function it returns 0.5. If we multiply it by let's just say 5, it would return 2.5. Also, the value won't just always be 0.5, so if we run Math.random() * 5 a couple times, it would be different numbers from 0 to 5 every time. I hope you understand!

Good luck, Alex

Thank You Alexander Davison, for taking your time to answer my question

After the a random number is selected, how the result is displayed in that box.?

What box?

Kegan Windle
Kegan Windle
2,217 Points

So does the math.random function or javascript assign a number to each answer? Or are the 4 answers in the box in order 0,1,2,3?