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.

script.js
for (i = 2; i > 2) {
  console.log( i );
}
index.html
<!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
seal-mask
PLUS
.a{fill-rule:evenodd;}techdegree
Shawn Denham
Python Development Techdegree Student 17,802 Points

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.

Shawn Denham
seal-mask
PLUS
.a{fill-rule:evenodd;}techdegree
Shawn Denham
Python Development Techdegree Student 17,802 Points

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!

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?

Shawn Denham
seal-mask
.a{fill-rule:evenodd;}techdegree
Shawn Denham
Python Development Techdegree Student 17,802 Points

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!

No problem!