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
erdragerdragsson
Courses Plus Student 5,887 PointsQuestion about a code line
Hello, i was wondering one thing about this line of code,
document.getElementById('quote').innerHTML = quotes[Math.floor(Math.random() * quotes.length) ]
Why do i have to put "[ ]" after "quotes" and at the end?
// erdrag
Zachary Green
16,359 Pointsthats how you access elements of an array. example you want the 3rd element of the qoutes array so you type quotes[2] which outputs thatquote
erdragerdragsson
Courses Plus Student 5,887 PointsOh yeah, know i remember!
thanks for sorting that out!
1 Answer
Zachary Green
16,359 Pointsis quotes an array. that is what it seems like and the code inside the [] will output a number to choose a quote. [] is a javascript array.
erdragerdragsson
Courses Plus Student 5,887 Pointserdragerdragsson
Courses Plus Student 5,887 PointsYeah, quotes is an array, but why do you put the random code inside [] marks?