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 trialjuned alam
Full Stack JavaScript Techdegree Student 4,107 Pointswhy do i get this wrong?
not sure if it is a bug, because i ran my code on both the console and a online javascript IDE and they both work. it sucks because i cant submit the unit project untill this i pass this challenge.
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>
1 Answer
Shehan Dissanayake
19,119 PointsThe answer should be console.log(players[0]);
Because it says to log the first player, not the 6 th. if you pass 5 inside [] it logs the 6th player in the array.
index 0 refers to the first values in an array. Thanks
juned alam
Full Stack JavaScript Techdegree Student 4,107 Pointsi was specifically referring to the second part of the challenge where it asks to log out the last item, turns out they wanted the solution on a second line, so it should have been: console.log(players[0]) console.log(players[5])
instead of how i just had console.log(players[5])
thanks
Shehan Dissanayake
19,119 PointsShehan Dissanayake
19,119 PointsThe answer should be console.log(players[0]);
Because it says to log the first player, not the 6 th. if you pass 5 inside [] it logs the 6th player in the array.
index 0 refers to the first values in an array. Thanks