Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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?