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 trialDavid Carr
3,042 PointsNeed 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);
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);
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JavaScript Loops</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
2 Answers
Julian Aramburu
11,368 PointsHi 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!
David Carr
3,042 PointsGot it, it's working now, thanks
Julian Aramburu
11,368 PointsCongratulations :)! Happy coding!
Mihai Andrei
6,325 PointsMihai Andrei
6,325 Pointstry this: i<list.length