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

loops are too confusing

I tried length?

script.js
var temperatures = [100,90,99,80,70,65,30,10];
for (var i = 0; i < temperatures; i+=100) 
{
 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>

3 Answers

Brendan Whiting
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Brendan Whiting
Front End Web Development Techdegree Graduate 84,738 Points

1) in the 2nd section of your for loop setup, you need to reference temperatures.length rather than temperatures. This section is a condition that needs to be true in order to keep looping, so as long as i is less than the length of the array.

2) in the 3rd section of your for loop setup, you need to increment by 1 every iteration, not by 100. You can do that with i++.

3) you need a closing parens ) after your console.log

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

thank you Brendan. I tried it with length but I was missing the closing parenthesis in the console log. I don't understand the difference between the ==, ++ and +=. is there someplace I could see all those defined? thanks again

Brendan Whiting
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Brendan Whiting
Front End Web Development Techdegree Graduate 84,738 Points

== or === is for comparison. You're asking if the thing on its left is the same as the thing on its right, and this expression will return true or false. This is distinct from = which is the assignment operator. It's saying put the thing to it's right inside the thing to its left.

+= is a shorthand. num += 5 is the same as saying num = num + 5, or add 5 to num.

++ is for incrementing by 1. num++ is the same as saying num += 1 (which is the same as num = num + 1)

Here's a master list of all the JavaScript operators.

how do you get the console to come up in workspace? it's not showing up

I think console statements written in challenge answers show up in the browser dev tools console panel. Have you tried looking there?

For some reason the console will not come up ajay. I've done everything treehouse has asked me to do. My copy and paste doesn't always work either. It's like its stuck.