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

scott Walker
scott Walker
2,506 Points

surely aslong as the array starts printing from position 0 this should work?

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.

is my error , im not sure how its skipping an item on the array .

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

for ( var i= 0 ; i < temperatures.length ; i += 1){
<!DOCTYPE html>
  <meta charset="utf-8">
  <title>JavaScript Loops</title>
<script src="script.js"></script>
Cheo R
Cheo R
37,150 Points

Looks like you need to sort your array before logging them out.

1 Answer

You are logging i when you should be using i as an index to log the temperatures

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

for ( var i= 0 ; i < temperatures.length ; i += 1){
garryl torres
garryl torres
1,090 Points

can someone explain as to why adding the array [i] after temperatures in the console.log works and not just console.log(temperatures) by itself? To me, it seems like it would just log the index value (0,1,2,3, etc..) and not the values ( 100, 90, 99, etc..). confused

i was overthinking it and thought that we would have to create a separate variable such as 'list' like the previous video. thanks in advance!