Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Loops, Arrays and Objects Tracking Multiple Items with Arrays Iterating through an Array

Victor Gordian
Victor Gordian
4,656 Points

Confused about this challenge

"Use a for or while loop to iterate through the values in the temperatures array from the first item -- 100 -- to the last -- 10. Inside the loop, log the current array value to the console." Now at first i knew i had to put

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

and it wouldn't let me go, so Im wondering what key term did i miss to have not thought about 1++ (which btw i don't know what '++' means) and only reason why i know its that is because i googled the question and someone had the answer. Im really confused.

Dan Johnson
Dan Johnson
40,532 Points

Added code tags.

You can see how to add them by clicking on the Markdown Cheatsheet link above the "post comment" or "post answer" button.

3 Answers

Hi Victor,

The code I used is exactly like yours, except you're using the "greater than" symbol instead of the "less than" symbol. You have "i >temperatures.length" instead of "i < temperatures.length"

Just change that and it will work. I tested it.

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,028 Points

Hi Victor,

Try changing your iteration operator from =+ to +=.

for(var i = 0; i > temperatures.length; i=+1)

At the moment you're assigning new values rather than interating through properly. :) Hope this helps

Victor Gordian
Victor Gordian
4,656 Points

Oh didn't notice, but the answer overall is instead of that its 1++ just wondering why

Dan Johnson
Dan Johnson
40,532 Points

In your for loop, you'll want to be checking if i is less than the length of the temperatures array. Checking if it's greater causes the loop to never execute, as i starts out at 0, and the length of the temperatures array is 8.

The ++ operator increments a value by 1. It can be either prefix:

// Returns the incremented value of i
++i

Or postfix:

// Returns the value of i, then increments i by 1.
i++

For the purpose of this loop it's equivalent to i += 1 either way.