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 How Your JavaScript Works Together

Mandaar Dahale
Mandaar Dahale
2,527 Points

function random_number

I understood purpose of all the functions except 'random_number'. couldn't figure out, for what purpose it is being used in code? just out of curiosity. please help!!

1 Answer

It is being used to select a random item from the array...so it says:

 var randomNumber = random_number(4);
return mash[randomNumber];

This selects a random item from the array, as there is 5 items in the array it will either be 0,1,2,3,4 item.