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 trialDaisho Komiyama
15,906 PointsJavaScript Loops, Arrays, Objects - Challenge Task 2 of 2 has an error console.log(players[5]); should work.
Question is ' Now, use console.log() to log out the last item in the array.' I typed as follows,
var players = ['Jim', 'Shawna', 'Andrew', 'Lora', 'Aimee', 'Nick']; console.log(players[5]);
but it won't work. I don't know why...
var players = ['Jim', 'Shawna', 'Andrew', 'Lora', 'Aimee', 'Nick'];
console.log(players[5]);
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JavaScript Loops</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
2 Answers
Daniel Newman
Courses Plus Student 10,715 PointsIt is quiz about anyArray.length method. Did you try to get it this way?
console.log(players[players.length]);
Oh, I've got it. This quizz ask you to provide two lines of code:
console.log(players[0]);
console.log(players[5]);
nathanielcusano
9,808 PointsThere is no need to add .length to players. It works fine without it.
Daisho Komiyama
15,906 PointsDaisho Komiyama
15,906 PointsOh! You're right! I had to add another line of code!
Thank you so much Daniel!