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 trialluisgomez7
5,557 PointsDoes Challenge Task 2 in JavaScript Loops, Arrays and Objects have a mistake in the software?
The question reads as follows: Use console.log() to log out the last item in the array. var players = ['Jim', 'Shawna', 'Andrew', 'Lora', 'Aimee', 'Nick'];
Here's my answer: console.log(players[5]);
I've tried all numbers from one through six and nothing works.
var players = ['Jim', 'Shawna', 'Andrew', 'Lora', 'Aimee', 'Nick'];
console.log (players[6]);
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JavaScript Loops</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
2 Answers
andren
28,558 PointsThe first index you tried (5) is indeed the correct one. The issue is that you have removed / changed the code you wrote in task 1. Below the challenge description of every task the following text is written:
Important: In each task of this code challenge, the code you write should be added to the code from the previous task.
What that is trying to tell you is that for multi-part challenges you should not remove previous parts, but add to them. When you try to check your code the challenge checker will run all of the tests from all of the tasks it has given you so far, and if your code does not pass all of them (not just the test for the current task) then it will be marked invalid.
So if you add the code for task 1 back like this:
var players = ['Jim', 'Shawna', 'Andrew', 'Lora', 'Aimee', 'Nick'];
console.log(players[0]);
console.log(players[5]);
Then your code will pass.
luisgomez7
5,557 PointsThanks