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 JavaScript Arrays Store Multiple Values in an Array Access Array Elements by Index

Can't get through Code Challenge: Access Array Elements by Index because of an error message.

I don't know what is wrong with my code, I think I'm following the instructions and doing it right.

script.js
const players = ['Toni', 'Anwar', 'Mali', 'Carlos', 'Cormac', 'Sariah'];
console.log(players[5]);

The instructions are: On the next line, use console.log() to log the last element inside the players array.

The error message: Bummer: Use [ ] and a number to access an item in an array. For example, players[1].

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Gerardo Espinoza! You're doing great here and clearly understand indexes. However, before you submit the code to be checked you should see this warning between the instructions and directly over the place where you code:

Important: In each task of this code challenge, the code you write should be added to the code from the previous task.

It seems you erased the line that printed the first one at index 0. There should be two console.log() lines to pass step 2. These challenges are cumulative and many require that you leave any previously passing code intact. Such is the case here.

Hope this helps! :sparkles:

Thanks, I had not noticed this before.