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

Why is this not working?

I cannot figure out why it is wrong.

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>
Saad Khan
Saad Khan
7,485 Points

Your code is fine, console.log() logs your data to the console - fire up the browser console and that is where you would see the value of the array. To otherwise display it in the body of the web page use:

document.write(players[5])

If this doesn't solve your issue, please elaborate your point further.

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! Your code is functional and correct. However, you have missed this tip given by Treehouse.

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

You've altered the code from the first step into code that passes the second step. What it wants is not one console.log(), but two. The code that passes step two will have a console.log that logs the first item in the array and a console.log that logs the last item.

Hope this helps! :sparkles:

Yaaaay! :sparkles: Thank you so much, both of you! How silly of me to alter the first code. That was indeed the problem!