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 trialWilfredo Casas
6,174 PointsWhy is my for loop not working?
Not sure why it isn't working
var temperatures = [100,90,99,80,70,65,30,10];
for (i=0; i <11; i+=1 ) {
console.log(i);
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JavaScript Loops</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
3 Answers
Jennifer Nordell
Treehouse TeacherHi there! I'm going to give some hints here. Hopefully, you can get the answer from these as I think it will be a better learning experience overall.
- Your code is currently logging out the numbers 0 to 10.
- Your code should be logging out the element in that position of the array where i is less than the length of the array
- You will need to access the array set up by the challenge like so
temperatures[i]
Good luck, but let me know if you're still stuck!
Craig Garner
25,732 PointsAdd a counter variable to do your counting. x = count.length
It won't break when you add more or less
Luiz Felipe Soares
13,840 PointsJust to be safe in the future, you can try to set i < temperature.length
, so you work with variables and minimise human error.
Always remember that "i" make reference to the index of your array in your case.
cheers
Wilfredo Casas
6,174 PointsWilfredo Casas
6,174 PointsHey Jennifer, your profile is impressive. May I ask how many hours a day do you come into Treehouse?
Jennifer Nordell
Treehouse TeacherJennifer Nordell
Treehouse TeacherWilfredo Casas I used to come here no less than 8 hours a day. It's been less recently and some days not at all. I'm currently working on some projects
Wilfredo Casas
6,174 PointsWilfredo Casas
6,174 PointsI take my hat off to you madam.