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

Raidel Rivero
Raidel Rivero
1,679 Points

What happened to Nick?

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

//Should return Nick right?

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>

Keep both of them together: try:

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

3 Answers

This works in the console for me.

Dane Parchment
MOD
Dane Parchment
Treehouse Moderator 11,075 Points

Are you actually running into errors or are you just asking if it should return Nick?

If it is the former, then what errors are you running into? The code you have provided should work perfectly fine!

If it is the latter, then yes it will return Nick, as Nick is in the 5th index.

Raidel Rivero
Raidel Rivero
1,679 Points

Thanks everyone! Stivan was right. My issue was that I did not keep both lines of code in sequence. Technically it should have worked but the interpreter did not accept it as the right answer. Once again thanks very much!