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

Shahzad Qadir
Shahzad Qadir
5,734 Points

Stuck at this error Bummer: Use [ ] and a number to access an item in an array. For example, `players[1]

I am actually accessing it using players[5] and it works on console but still I am getting this error.

Any ideas?

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

2 Answers

Steven Parker
Steven Parker
229,920 Points

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

Assuming you're on task 2, you've solved it but you also removed the line that solves task 1. Both lines must be present for the solution to pass.

And if you're still on task 1, it asks you to log "the first name inside the array" but this code logs the last one.

Shahzad Qadir
Shahzad Qadir
5,734 Points

Thanks Steven. My issue was, I had removed task 1 solution, It started working when I added that back in.