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

what's wrong here I made everything correct

here is the Bummer hat was told: (Bummer! You didn't log out the even numbers from 2 to 24)

script.js
for ( var i = 2; i <= 12; i += 1 ) {
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>

4 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! You have a good start, and your syntax is spot on but it's not doing what you think it's doing. It should be printing out all even numbers between 2 and 24 (inclusive). However, your code prints out all numbers between 2 and 12 (inclusive). It's even printing out the odd ones. I encourage you to run your code in the console and take a look at what it's producing.

I wrote it like this:

for ( var i = 2; i <= 24; i += 2 ) {
console.log( i )  
}

This starts our count with 2 and goes up to 24 (inclusive). Then we increment by two each time (as opposed to 1).

Hope this clarifies things! :sparkles:

Hey

Almost there.

for (var i = 2; i < 25; i += 2) {
  console.log(i);
}

This sets i to 2. Then loops +=2 until it is less than 25. Hope this helps

Happy coding

Paul

it isn't 25 it is 24 though but thanks for your support too :)

Yeah. Mine works also but I think Jennifers is best practice though. :)

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Yes, your does work and I don't believe either one of ours is really "best practice". I'm of the opinion that it doesn't matter. I was just attempting to keep the code as close to the original as possible :smiley:

Thank you both for your support :)

Happy Coding