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 trialPatrick Franklin
Full Stack JavaScript Techdegree Student 2,025 Pointsnothin works for this ...
for ( i=2 ; i<25 ; i+=2 ) { console.log(i); }
console.log(2);
console.log(4);
console.log(6);
console.log(8);
console.log(10);
console.log(12);
console.log(14);
console.log(16);
console.log(18);
console.log(20);
console.log(22);
console.log(24);
for(i = 2 ; i <= 25; 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>
2 Answers
tobiastrinkler
Full Stack JavaScript Techdegree Student 16,538 PointsHi Patrick, you almost got it , but you forgot to declare the variable with the var keyword.
Furhtermore, you can see if you log out the loop to the console the last value is undefined as you are checking if the number is smaller or equal to 25 which is not possible since you are always increasing your counter by 2 and 25 is not an even number hence try <=24.
for(var i =2; i<= 24;i+=2){
console.log(i)
}
Antti Lylander
9,686 PointsYour code is fine but you need to delete these lines:
console.log(2);
console.log(4);
console.log(6);
console.log(8);
console.log(10);
console.log(12);
console.log(14);
console.log(16);
console.log(18);
console.log(20);
console.log(22);
console.log(24);
Antti Lylander
9,686 PointsAntti Lylander
9,686 PointsWell, it works just as well with
i <=25
and passes the challenge. You will get the 'undefined' anyway even if you usei <= 24
ori <= 999
or if you changei += 2
toi += 1
.The 'undefined' on the last line in console means that the function is not defined to return anything.