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 Loops, Arrays and Objects Tracking Multiple Items with Arrays Iterating through an Array

S Ananda
S Ananda
9,474 Points

Stuck on Iterating through arrays challenge

Not doing something right to console log my list. Hints would be nice. Am I trying to make it too simplistic?

script.js
var temperatures = [100,90,99,80,70,65,30,10];
for (i = 0; i < temperatures.length; i ++);
 console.log(temperatures);
index.html
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JavaScript Loops</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>

2 Answers

Nicholas Vogel
Nicholas Vogel
12,318 Points

Your for loop isn't done correctly. You need to have an opening and closing curly brace, and that ; at the end of the for condition is unnecessary.

S Ananda
S Ananda
9,474 Points

Thanks for the help. I must have been too tired to see my error, yesterday. It worked perfectly as soon as I added the curly braces and added back in the [i] in the console log.

Margarita Osmani
Margarita Osmani
21,286 Points

First of all, you need squiggly brackets after if ().

You're really close but missing something. Try the following code:

var temperatures = [100,90,99,80,70,65,30,10]; for (i = 0; i < temperatures.length; i ++) { console.log(temperatures[i]); }

You need the square brackets [i] in order to know which array item you want to print to the console. I hope I could help.

S Ananda
S Ananda
9,474 Points

Thanks Margarita. I had the [i] in at one time and it didn't work, so I took it out. I forgot to add it back in when I asked my question. It was the curly braces I was missing. Sometimes something is so obvious you can't see it (like a huge syntax error!).