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

Array Not in Order

This is my code for this challenge. It keeps telling me it's not in order. Please tell me what I'm doing incorrectly.

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

5 Answers

Are you sure you are not missing the "[i]" in console.log(temperatures[i])?

When I remove it from my code I get the same error you are seeing.

I don't know where my mistake was, but I just copied your code and it worked. I had the [i] in there, but I must have had something else out of place or missing.

Thank you again. Until that issue, arrays were making a lot of sense to me.

That is exactly what I have and I still keep getting this message:

"The items in the array weren't logged out in order. Your should log all the temperatures in order, starting at 100 and ending at 10."

Your for loop is not set up correctly.

It needs to know where to start; var i = 0. When to stop: at the end of the array And how big of a step to take each iteration. (in this case 1)

for(var i = 0; i<temperatures.length; i++) {
  //Code for inside loop goes here.
}

Edit: On second thought your for loop may just be formatted incorrectly since your not using the markdown for code. A second issue I'm seeing is your console.log. You are logging out the entire array instead of just one index of the array.. You are using the for loop to cycle through the indices so it should look like: console.log(temperatures[i]);

I don't know why my code came looking out like that... It actually looks like this:

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

The issue is it keeps giving me the following reason for why it is incorrect: "The items in the array weren't logged out in order. Your should log all the temperatures in order, starting at 100 and ending at 10."

Any idea what I'm doing incorrectly?

And thanks for the help. I was just burnt out last night and had to call it for the evening.

No worries. All together it looks like this.

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

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

No worries man. These challenges are like that sometimes have a comma instead of a semicolon or whatever. As you can't see the output of your code directly makes it hard to troubleshoot. Have had many a headache with these quizzes on material I understand as well.