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

Lucas Santos
Lucas Santos
19,315 Points

This task is not passing me, I have the correct answer.

Now, use console.log() to log out the last item in the array.

var players = ['Jim', 'Shawna', 'Andrew', 'Lora', 'Aimee', 'Nick'];
console.log(players[5]);

Not letting me pass and I have no idea why.. I even tried players.length

index.html
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JavaScript Loops</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>

3 Answers

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

Yea this one has the potential to catch one or 2 out.

You need to make sure you keep the answer to the first task in the code. So answer the second part like this.

var players = ['Jim', 'Shawna', 'Andrew', 'Lora', 'Aimee', 'Nick'];
console.log(players[0]);
console.log(players[5]);
Lucas Santos
Lucas Santos
19,315 Points

They should really change that to let you pass if it has that extra line or not.

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,253 Points

Possibly. But there is the notice in each challenge that the code from the last challenge should be added to. That said the doubt is definitely there whether to add a second log or just change the array idnex. Thankfully I got it right on my first go.

Maybe send some feedback to Dave on the Stage feedback button. :-)

Anusha Lee
Anusha Lee
Courses Plus Student 14,787 Points

Thank you, Jonathan. I got this problem, too. Now I finally pass.

Just had the same problem. This can be easily fixed with clearer instructions.

Walt Ribeiro
Walt Ribeiro
4,496 Points

When this challenge loads, the original code is no present. So there's no way of knowing why there's an error. This challenge should be updated to reflect a correct answer when the original code is not present.