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 trialMandaar Dahale
2,527 Pointsfunction 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
Liam Walls
7,998 PointsIt 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.