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 trialGerardo Espinoza
930 PointsCan'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'];
console.log(players[5]);
1 Answer
Jennifer Nordell
Treehouse TeacherHi 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!
Gerardo Espinoza
930 PointsThanks, I had not noticed this before.
Gerardo Espinoza
930 PointsGerardo Espinoza
930 PointsThe 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]
.