Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Loops, Arrays and Objects Tracking Multiple Items with Arrays Using Array Indices

Yan Malyakov
Yan Malyakov
2,371 Points

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

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

i understand it is simple question but i try write answer //1) console.log(5); //2) var players = ['Jim', 'Shawna', 'Andrew', 'Lora', 'Aimee', 'Nick']; var lastItem = players[5] ; console.log(lastItem); //3) console.log(players.length - 1); please help it doesn't work

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

5 Answers

Adam Beer
Adam Beer
11,304 Points

Simple. Please delete this 2 lines. You dont need it.

var lastItem = players[5] ; 
console.log(lastItem);

Use only 2 console.log. Inside the first console.log log the first element and inside the second console.log log the fifth element. I hope this help!

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

Enjoy the coding!

Adam Beer
Adam Beer
11,304 Points

Hi Yan! When you log the first item in array give the index of property. Like this: console.log(players[0]); I Hope this help!

Adam Beer
Adam Beer
11,304 Points

The fifth element was saved in var lastItem. After inside the console.log log the fifth element in array. Use player(this is the variable name) in the console.log and add index of property.

Yan Malyakov
Yan Malyakov
2,371 Points

Adam,hello i write
console.log(players[5]); it answer me Oops! It looks like Task 1 is no longer passing. if i write console.log(players[5]); it answer me Bummer! Use [ ] and a number to access an item in an array: players[0] where is the problem..please answer me.

Adam Beer
Adam Beer
11,304 Points

Hihi. Tricky task. Dont use second time the first console.log, write new console.log to fifth element. Good coding! :)

Yan Malyakov
Yan Malyakov
2,371 Points

var players = ['Jim', 'Shawna', 'Andrew', 'Lora', 'Aimee', 'Nick']; var lastItem = players[5] ; console.log(lastItem); //it does'nt work //or var players = ['Jim', 'Shawna', 'Andrew', 'Lora', 'Aimee', 'Nick']; console.log(players[5]); //it does'nt work //or var players = ['Jim', 'Shawna', 'Andrew', 'Lora', 'Aimee', 'Nick']; console.log(players.leth - 1); //it does'nt work //please what I write wrong ?