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 trialzkb
Front End Web Development Techdegree Graduate 13,636 PointsWhy isn't my code logging the even numbers 2 through 24 to the console?
Hello, I'm absolutely stuck and can't figure out what's wrong with my code. Thank you for your help.
for ( let i = 2; i <= 24; i += 2 ) {
console.log(`${i}`);
}
1 Answer
Clayton Perszyk
Treehouse Moderator 48,850 PointsLooks like it's testing that the output is a number, but the code you've written is outputting a string.
Gremyko Coleman
9,756 PointsGremyko Coleman
9,756 PointsThe "if" statement will only even numbers because the % in JavaScript, divides a number and returns its remainder after the division.
ex)
2 / 2 = 0 , has no remainders , so it will meet the condition of "0" and will pass to the console
2 / 3 = has a remainder of 1 , so it doesn't meet the condition of 0 , so it will not be passed to the console