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 trialYan Malyakov
2,371 PointsNow, 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
var players = ['Jim', 'Shawna', 'Andrew', 'Lora', 'Aimee', 'Nick'];
var lastItem = players[5] ;
console.log(lastItem);
<!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
11,314 PointsSimple. 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]);
Yan Malyakov
2,371 PointsI thank you Adam !
Adam Beer
11,314 PointsEnjoy the coding!
Adam Beer
11,314 PointsHi 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
11,314 PointsThe 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
2,371 PointsAdam,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
11,314 PointsHihi. Tricky task. Dont use second time the first console.log, write new console.log to fifth element. Good coding! :)
Yan Malyakov
2,371 Pointsvar 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 ?