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 trialAndrew Nicholson
2,474 PointsI'm a bit lost as to how to make this log 12 times
Shouldn't the "i <= 24; i +=2" part make this log 12 times?
what have I missed?
Thanks. Beginning to think JS is beyond me.
for ( var i = 0; i <= 24; 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>
4 Answers
Brandon Ashcraft
10,259 PointsSyntax syntax syntax. Here's what it should be. In trade, can you tell me the difference between mine and yours?
for (var i=2; i<=24; i+=2){
console.log(i)
};
Ben Farr
3,834 PointsSet your 'var i = 0;' to 'var i = 2;'. That should solve your problem. Just remember that the initial 'i' in the for loop is your beginning point, and will be counted as one of the loop rotations. I hope this makes sense! P.S. I put that first comment in the wrong section. My apologies!
Brandon Ashcraft
10,259 PointsAlso, (if you haven't already) remember to remove all of the other 'console.log' functions written into the exercise before submitting your code. That's what burned me on that one :)
JS is fickle, but don't give up. You may need to learn a different way than how it is taught here. Look at some other resources that teach JS or have practice exercises for you to work with.
Andrew Nicholson
2,474 PointsHi, thanks Ben and Brandon, I've changed the 0 to a 2 and this still says it only logs once. I think I initially did have the "2" as the inital "i" value, but changed it because it wouldn't work.
I might try restarting chrome and trying again.
Michael Oliver
7,855 Pointsyou will also want the last number to be 26 not 24.
Andrew Nicholson
2,474 PointsAndrew Nicholson
2,474 Pointsomg thanks so much - i knew i had it right, just couldn't work it out!!
(the semicolon was inside the curly braces)