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

Iterating through an array quiz

Hi! I don't know what I'm doing wrong, but it keeps saying that I'm not logging my array items in order. Any help would be great!

Thanks! -Rachel

script.js
var temperatures = [100,90,99,80,70,65,30,10];
function printList(list) {
  for(i = 0; i < list.length; i += 1) {
    console.log(i);
  }
}
printList(temperatures);
index.html
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JavaScript Loops</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>

Hi Rachel,

I think you're almost there: in the temperatures variable you have 90 between 100 & 99, instead of between 99 & 80.

Good luck!

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

This one line is the culprit!

console.log(i);

Here, you're printing out the value of i. Not the value at the list index of i. The line you need is:

console.log(list[i]);

It worked!!! Thank you!!!!!!

Jared Brandon
Jared Brandon
8,674 Points

Can you explain why this prints them out in order by value? I don't understand where the program is being told to do that. Thanks!

Duh me. Great eye Jennifer!