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

Justin Oswald
Justin Oswald
5,969 Points

out of ideas

Im not sure what I am missing in this code for it to pass

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

for(var i = 0; i>= temperatures.length; i +=1 ) {
    console.log(temperatures[i])
}
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

Travis Batts
Travis Batts
4,031 Points

Almost got it Justin. Looks like your boolean is backwards.

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

for(var i = 0; i <= temperatures.length; i +=1 ) { console.log(temperatures[i]) }

This looks like what you're after.

So change your >= to <=.

Justin Oswald
Justin Oswald
5,969 Points

Thank you it seems the error is always something obvious that only I cannot see haha

jeffrey bachynski
jeffrey bachynski
5,179 Points

Hint: Is i greater than or equal to temperatures.length?

Travis Batts
Travis Batts
4,031 Points

Well In my code I place "I" as being "less" than temperatures.length. In your code you have "I" as being "greater than".

var i = 0, so "I" can not be greater than temperatures.length in this case.

Justin Oswald
Justin Oswald
5,969 Points

Thank you it seems the error is always something obvious that only I cannot see haha

Justin Oswald
Justin Oswald
5,969 Points

Thank you it seems the error is always something obvious that only I cannot see haha

jeffrey bachynski
jeffrey bachynski
5,179 Points

@Travis, I can see that you wrote it correctly. I was trying to give Justin a hint. We both answered at about the same time. Sorry for the confusion.

Travis Batts
Travis Batts
4,031 Points

@Jeffrey. Lol I honestly did not pay attention to the names at all. I thought you were the OP (nor did I fully read the response). That is my mistake sorry about that.