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 trialVictor Gordian
4,656 PointsConfused about this challenge
"Use a for or while loop to iterate through the values in the temperatures array from the first item -- 100 -- to the last -- 10. Inside the loop, log the current array value to the console." Now at first i knew i had to put
var temperatures = [100,90,99,80,70,65,30,10];
for(var i = 0; i > temperatures.length; i=+1){
console.log( temperatures[i] );
}
and it wouldn't let me go, so Im wondering what key term did i miss to have not thought about 1++ (which btw i don't know what '++' means) and only reason why i know its that is because i googled the question and someone had the answer. Im really confused.
3 Answers
Brooke Janssens
8,090 PointsHi Victor,
The code I used is exactly like yours, except you're using the "greater than" symbol instead of the "less than" symbol. You have "i >temperatures.length" instead of "i < temperatures.length"
Just change that and it will work. I tested it.
Jonathan Grieve
Treehouse Moderator 91,253 PointsHi Victor,
Try changing your iteration operator from =+ to +=.
for(var i = 0; i > temperatures.length; i=+1)
At the moment you're assigning new values rather than interating through properly. :) Hope this helps
Victor Gordian
4,656 PointsOh didn't notice, but the answer overall is instead of that its 1++ just wondering why
Dan Johnson
40,533 PointsIn your for loop, you'll want to be checking if i is less than the length of the temperatures array. Checking if it's greater causes the loop to never execute, as i starts out at 0, and the length of the temperatures array is 8.
The ++
operator increments a value by 1. It can be either prefix:
// Returns the incremented value of i
++i
Or postfix:
// Returns the value of i, then increments i by 1.
i++
For the purpose of this loop it's equivalent to i += 1
either way.
Dan Johnson
40,533 PointsDan Johnson
40,533 PointsAdded code tags.
You can see how to add them by clicking on the Markdown Cheatsheet link above the "post comment" or "post answer" button.