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 trialEmis Zakitis
139 Pointsthis is RIght ?=
It says I have to make a console.log form 2 to 24 with a loop. i did it? plz help
for ( i = 2; i <24; i++){
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
Steven Parker
231,248 PointsIt looks like you're really close, but the challenge asks for just the even numbers. Using "i++
" as the increment expression will give you every number in your range.
Also, if you want the end number included, you need a "<=
" comparison instead of "<
".
Raymond Ramos
6,445 Pointsif you want it to go all the way to 24, then you have to make i <= 24 the way that you have it right now stops when it checks if 24 < 24 and since it is not it does not print to the console
matth89
17,826 PointsIt's asking you to log only the even numbers, so you need to increment i by 2 instead of one. Also, you need to change your evaluation of "i < 24" to "i < 25" so it will log the final number.
Emis Zakitis
139 PointsIt says: The code below logs all of the even numbers from 2 to 24 to the JavaScript console. However, there's a lot of redundant code here. Re-write this using a loop.
and then there is:
conlsole.log (1); conlsole.log (2); etc.
I dont know What I have to do defferent
Steven Parker
231,248 PointsLook again, the original code does not log "1", or any odd number.
Charles Buckley
21,669 Pointsfor(var i = 2; i < 25; i += 2){ console.log(i); }
Steven Parker
231,248 PointsFYI: Explicit answers without any explanation are strongly discouraged by Treehouse and may be subject to redaction by moderators.
Emis Zakitis
139 PointsEmis Zakitis
139 PointsIt doesn't ask for even numbers... got any other ideas, I changed it to <=.
Steven Parker
231,248 PointsSteven Parker
231,248 PointsBut it does! The first line of the instructions says: "The code below logs all of the even numbers from 2 to 24 to the JavaScript console.". Your task is to do the same thing in a loop.
Emis Zakitis
139 PointsEmis Zakitis
139 PointsThis is embarrassing, You had right all the way... sryy.