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 trialKim Dallas
11,461 Pointsloops are too confusing
I tried length?
var temperatures = [100,90,99,80,70,65,30,10];
for (var i = 0; i < temperatures; i+=100)
{
console.log (temperatures[i];
}
<!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
Front End Web Development Techdegree Graduate 84,738 Points1) 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]);
}
Kim Dallas
11,461 Pointshow do you get the console to come up in workspace? it's not showing up
Ajay Prasannan
16,002 PointsI think console statements written in challenge answers show up in the browser dev tools console panel. Have you tried looking there?
Kim Dallas
11,461 PointsFor 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.
Kim Dallas
11,461 PointsKim Dallas
11,461 Pointsthank 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
Front End Web Development Techdegree Graduate 84,738 PointsBrendan 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 sayingnum = num + 5
, or add 5 tonum
.++
is for incrementing by 1.num++
is the same as sayingnum += 1
(which is the same asnum = num + 1
)Here's a master list of all the JavaScript operators.