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 Simplify Repetitive Tasks with Loops Refactor Using a Loop

This 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>
  <meta charset="utf-8">
  <title>JavaScript Loops</title>
<script src="script.js"></script>

2 Answers

You 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 );

Wow! I have to say I'm a little proud of myself for getting that far! Thanks a ton!

Hmm. I wrote that code in my editor, but it still won't work.

but 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 :)

Ahh, I forgot about that part. I think I was thinking that I needed to just make an infinite evens number counter. Thanks again!

Do you understand what that for loop is doing? If not we can go though it step by step if you like.

No 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.

Would you know why it's only logging a single number?

haha 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

Great, I just figured it out! Thanks again!

AWESOME! sorry we had to get there the long way! haha

No problem!