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 Loops, Arrays and Objects Tracking Multiple Items with Arrays Using Array Indices

juned alam
seal-mask
.a{fill-rule:evenodd;}techdegree
juned alam
Full Stack JavaScript Techdegree Student 4,107 Points

why do i get this wrong?

not sure if it is a bug, because i ran my code on both the console and a online javascript IDE and they both work. it sucks because i cant submit the unit project untill this i pass this challenge.

script.js
var players = ['Jim', 'Shawna', 'Andrew', 'Lora', 'Aimee', 'Nick'];
console.log(players[5]);
index.html
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JavaScript Loops</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
Shehan Dissanayake
Shehan Dissanayake
19,119 Points

The answer should be console.log(players[0]);

Because it says to log the first player, not the 6 th. if you pass 5 inside [] it logs the 6th player in the array.

index 0 refers to the first values in an array. Thanks

1 Answer

Shehan Dissanayake
Shehan Dissanayake
19,119 Points

The answer should be console.log(players[0]);

Because it says to log the first player, not the 6 th. if you pass 5 inside [] it logs the 6th player in the array.

index 0 refers to the first values in an array. Thanks

juned alam
seal-mask
.a{fill-rule:evenodd;}techdegree
juned alam
Full Stack JavaScript Techdegree Student 4,107 Points

i was specifically referring to the second part of the challenge where it asks to log out the last item, turns out they wanted the solution on a second line, so it should have been: console.log(players[0]) console.log(players[5])

instead of how i just had console.log(players[5])

thanks