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 trial

JavaScript JavaScript Quickstart Arrays and Loops Create an Array

Can't log array

var snacks = ["chips", "pop", "salsa"];

console.log(snacks[2]);

trying to log the 3rd item should be simple but I'm struggling new to javascript sorry. everything online says I'm doing it properly plz help

script.js
var snacks = ["chips", "pop", "salsa"];

console.log(snacks[2]);
index.html
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JavaScript Arrays</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>

2 Answers

Steven Parker
Steven Parker
231,275 Points

It looks like you might have tasks 2 and 3 mixed up. As Brendan pointed out, task 2 was to log the first item. And task 3 is to show the third item, but by using the alert function.

But there's also this warning given by every challenge: "Important: In each task of this code challenge, the code you write should be added to the code from the previous task.". So the work you do for task 2 should remain as-is when you write the code for task 3 on a separate line.

thanks I was moving to fast and missed the part about keeping previous work thanks