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

Valerie Smith
PLUS
Valerie Smith
Courses Plus Student 5,244 Points

Using a list var in printing array in the console. Challenge 1 Help?

Working on Challenge 1 and they are asking me to take a list of temps and iterate them in order from first to last on the console log. Please take a look at my attempt. I am honestly copying from the video because I assumed I would just need a for loop. but it shot it back at me saying they could not find a list variable. What is the point of the list variable? It is not asking for an ordered list of the items or I would create one. If you could just explain what the question is really asking that might help! :) Thanks everyone!

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

function list ( message ) { console.log (message); }

for (var i = 0; i < list.lenth; i+= 1){ console.log(temperatures[i]); }

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

function list ( message ) {
  console.log (message);
}

for (var i = 0; i < list.lenth; i+= 1){
  console.log(temperatures[i]);
}
index.html
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JavaScript Loops</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
Mike Henry
Mike Henry
Courses Plus Student 5,373 Points

If that fixed it please give me an up vote for best answer. I trying to get my stats up. Thanks

2 Answers

Mike Henry
PLUS
Mike Henry
Courses Plus Student 5,373 Points

var temperatures = [100,90,99,80,70,65,30,10]; function list ( message ) { console.log (message); }

for (var i = 0; i < temperatures.length; i+= 1){ list(temperatures[i]); }

There were 3 things: length misspelled, need the length of temperatures not list, need to pass temperature[i] to the list function.

I hope this helps.

Valerie Smith
PLUS
Valerie Smith
Courses Plus Student 5,244 Points

Mike thanks for the help. the spelling error and the .length value have been changed.