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

Need help with JavaScript Loops, Arrays and Objects - Iterating through an array

I am attempting to iterate through this array with a for loop on a code challenge.

Not sure where I am going wrong but I keep getting an error that it needs to iterate all the temperatures or a communication error.

function listTemp(list){ for(var i = 0; i = list.length; i += 1){ console.log(list[i]); } }

var temperatures = [100,90,99,80,70,65,30,10];

listTemp(temperatures);

script.js
function listTemp(list){
  for(var i = 0; i = list.length; i += 1){
    console.log(list[i]);
  }
}

var temperatures = [100,90,99,80,70,65,30,10];

listTemp(temperatures);
index.html
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JavaScript Loops</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
Mihai Andrei
Mihai Andrei
6,325 Points

try this: i<list.length

2 Answers

Julian Aramburu
Julian Aramburu
11,368 Points

Hi David! The problem here is you are using the equal operator in your second stage of the for loop you are setting i to temperature.length where generally you want to test if i is less than or greater than something! Check it and let me know if you have any additional problem!

Cheers!

Got it, it's working now, thanks

Julian Aramburu
Julian Aramburu
11,368 Points

Congratulations :)! Happy coding!