Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.

const players = ['Toni', 'Anwar', 'Mali', 'Carlos', 'Cormac', 'Sariah'];

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
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.