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 Stuff You Can Change

Anas Rida
Anas Rida
8,183 Points

the numbers

why did Joy first call the numbers and then multiplied then by a decimal and then rounded them down?? why not just call the numbers in the array?? Many thanks

edit: I am sorry, the part I am referring to is in the previous video. Mash random numbers. Joy uses a random numbers function to pull varaibles from the array.

Steven Parker
Steven Parker
230,274 Points

Can you give a time index for this video for what you describe? I'm not seeing anything like that.

1 Answer

Steven Parker
Steven Parker
230,274 Points

The idea is to pick a random number. The Math.random function always gives a decimal number between 0 and 1, so if you want a wider choice you multiply it by the number of choices. Then, you round down because you want to use this random choice as an array index, and the index cannot be a decimal.

I'm not sure what you mean by "call the numbers in the array" but I can only assume that there is no function that does it.