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 trialGabriel E
8,916 PointsThis code doesn't look right. Any ideas?
So I'm working on this challenge, and this is where I've gotten so far. I don't think most of it is correct, so could someone give me a helpful hint.
for (i = 2; i > 2) {
console.log( i );
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JavaScript Loops</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
2 Answers
Shawn Denham
Python Development Techdegree Student 17,801 PointsYou are REALLY close. Your forgot to put the code to decrease your counter each time though!
for (i = 2; i > 2; i -=) {
console.log( i );
}
Shawn Denham
Python Development Techdegree Student 17,801 Pointsbut you still won't pass :) it is asking you print number from 2 to 24. so You are going to want to create a counter that equals 2, prints that number then increase the count by 2 then prints that number etc...
for (i = 2; i <= 24; i+=2) {
console.log( i );
}
edit: had to correct a little typo in the code i+=2 not i+=24 :)
Gabriel E
8,916 PointsAhh, I forgot about that part. I think I was thinking that I needed to just make an infinite evens number counter. Thanks again!
Shawn Denham
Python Development Techdegree Student 17,801 PointsDo you understand what that for loop is doing? If not we can go though it step by step if you like.
Gabriel E
8,916 PointsNo I think I understand it now! The console says I'm only logging 1 number, though. Guess I'll have to go through and look at the numbers more carefully.
Gabriel E
8,916 PointsWould you know why it's only logging a single number?
Shawn Denham
Python Development Techdegree Student 17,801 Pointshaha yeah I had a typo myself I set i+=24 instead of i+=2 so it was going through and printing the number 2 then it increased i by 24 so that made i=26 and popped out of the loop just printing one number :)
everyone typos :D
Gabriel E
8,916 PointsGreat, I just figured it out! Thanks again!
Shawn Denham
Python Development Techdegree Student 17,801 PointsAWESOME! sorry we had to get there the long way! haha
Gabriel E
8,916 PointsNo problem!
Gabriel E
8,916 PointsGabriel E
8,916 PointsWow! I have to say I'm a little proud of myself for getting that far! Thanks a ton!
Gabriel E
8,916 PointsGabriel E
8,916 PointsHmm. I wrote that code in my editor, but it still won't work.