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 trial3 Answers
Gunhoo Yoon
5,027 PointsI think you are asking the wrong question. The number you are interested are called even numbers
for (var i = 2; i <= 24; i += 2 ) {
console.log(i)
}
Just in case odd number would be
for (var i = 1; i <= 25; i += 2) {
console.log(i)
}
How does this work? for loop can be verbally described as follow.
for (initialize; condition; change)
initialize: assign loop variable
condition: set stop condition
change: any changes you want to make for each iteration. This is typically used as a primary way to make your initial loop variable to reach stopping condition.
ginopino
16,320 Pointsfor (var i = 1; i <= 12; i++)
console.log(2 * i);
Julian Aramburu
11,368 PointsOr you could always take a shortcut and copy paste code :)
Julian Aramburu
11,368 PointsHi Amber! Are you referring to that particularly challenge? There you are asked to refactor that bunch of console.logs in order to do the same but with less code and you are hinted to use a loop to do so... so you could use a for loop maybe? and if you want to check if a number is even or not you could use modulus/reminder operator https://goo.gl/kab7qj!
If you are still lost after this, comeback for more help/hints!
Hope it helps you sort the problem out!
Cheers and Keep Coding!