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

How do i display these numbers in order?

i can get the numbers to display, but they are not in order.

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

9 Answers

Order of values in array is not important. Everything you need is:

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

I understand, but the task asks me to put the numbers in order.

Bummer! 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.

In challenge you need to:

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.

Or I am looking on another challenge?

thats the right challenge

Try to add the following:

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

Or

temperatures.sort(function(a, b){return b-a});
for (i = 0; i < temperatures.length; i++) { 
    console.log(temperatures[i]);
}

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

} console.log(temperatures);

this code prints out this:

[100, 90, 99, 80, 70, 65, 30, 10]

but i still get this error:

Bummer! 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.

Please, use Markdown Cheatsheet for formatting your post. It's very hard to read your code.

your code worked, Tnx

you are welcome

''' temperatures.sort(function(a, b){return b-a}); for (i = 0; i < temperatures.length; i++) { console.log(temperatures[i]); } '''

Im trying to figure out how to use the cheat sheet!!

You need to write code inside backquotes `

You can find this button above Tab

temperatures.sort(function(a, b){return b-a});
for (i = 0; i < temperatures.length; i++) { 
    console.log(temperatures[i]);
}
temperatures.sort(function(a, b){return b-a});
for (i = 0; i < temperatures.length; i++) { 
    console.log(temperatures[i]);
}

Ahh :) thanks again

You are welcome ;)

May the Force be with you, young Padawan

Obi Wan??

Qui-Gon =))