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 trialJules Al
1,096 PointsNot quite sure where I'm going wrong
I need to console.log all even #'s from 2-24... could someone help me understand what I'm doing wrong here? Thank you! Code is as follows:
function evens() { for(i=2; i<=24; i += 2); console.log(i) }
evens();
function evens() {
for(i=2; i<=24; i += 2);
console.log(i)
}
evens();
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JavaScript Loops</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
2 Answers
Jason Anders
Treehouse Moderator 145,860 PointsHi Juliann,
You're on the right track, but the challenge wants you to write a for loop
only (you also wrote a function). Just delete everything that is not directly part of the for loop
and you're good to go.
Challenges are VERY specific and VERY picky. If you add something that isn't asked for, it will not pass you.
for (var i = 2; i <= 24; i += 2) {
console.log(i);
}
Welcome to Treehouse. Keep Coding! :)
rdaniels
27,258 PointsThis passed the challenge:
for (i = 2; i <= 24; i += 2){
console.log(i);
}
Hope this helps...
Jules Al
1,096 PointsJules Al
1,096 PointsGot it, thank you!