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

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!