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

Brad Richardson
PLUS
Brad Richardson
Courses Plus Student 1,843 Points

How do i display these numbers in order?

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

Brad Richardson
Brad Richardson
Courses Plus Student 1,843 Points

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

9 Answers

Sergey Podgornyy
Sergey Podgornyy
20,660 Points

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

for (i = 0; i < temperatures.length; i++) { 
    console.log(temperatures[i]);
}
Brad Richardson
Brad Richardson
Courses Plus Student 1,843 Points

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.

Sergey Podgornyy
Sergey Podgornyy
20,660 Points

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?

Sergey Podgornyy
Sergey Podgornyy
20,660 Points

Try to add the following:

temperatures.sort();
temperatures.reverse();
for (i = 0; i < temperatures.length; i++) { 
    console.log(temperatures[i]);
}
Sergey Podgornyy
Sergey Podgornyy
20,660 Points

Or

temperatures.sort(function(a, b){return b-a});
for (i = 0; i < temperatures.length; i++) { 
    console.log(temperatures[i]);
}
Brad Richardson
PLUS
Brad Richardson
Courses Plus Student 1,843 Points

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.

Sergey Podgornyy
Sergey Podgornyy
20,660 Points

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

Brad Richardson
PLUS
Brad Richardson
Courses Plus Student 1,843 Points

''' 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!!

Sergey Podgornyy
Sergey Podgornyy
20,660 Points

You need to write code inside backquotes `

You can find this button above Tab

Brad Richardson
PLUS
Brad Richardson
Courses Plus Student 1,843 Points
temperatures.sort(function(a, b){return b-a});
for (i = 0; i < temperatures.length; i++) { 
    console.log(temperatures[i]);
}
Brad Richardson
PLUS
Brad Richardson
Courses Plus Student 1,843 Points
temperatures.sort(function(a, b){return b-a});
for (i = 0; i < temperatures.length; i++) { 
    console.log(temperatures[i]);
}
Sergey Podgornyy
Sergey Podgornyy
20,660 Points

You are welcome ;)

May the Force be with you, young Padawan