Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Loops, Arrays and Objects Simplify Repetitive Tasks with Loops Refactor Using a Loop

what is the syntax error

I am suppose to write a for loop therefore I can eliminate the 24 console.log statements but this code is not passing what is the problem.

for (let i = 0; i < 24; i+=2) {

<!DOCTYPE html>
  <meta charset="utf-8">
  <title>JavaScript Loops</title>
<script src="script.js"></script>

3 Answers

David McNeill
David McNeill
44,425 Points

Hey Christopher,

It looks like the code challenge may not accept the use of 'let' as a keyword, it expects 'var' instead. It might be an older JS course before ES2015 terms like 'let' or 'const' would have been acceptable as answers. So you haven't done anything wrong! The course might just need updating, certainly the more recent JS courses use ES2015 syntax a lot more.

Just FYI, you should also initialise your counter variable at 2, not 0. The challenge is expecting the first log value to be 2.

Good luck!

Thank you David.

Steven Parker
Steven Parker
215,269 Points

There's no syntax error from the standpoint of ES2015, but this challenge validator apparently does not recognize the newer keywords. Try using "var" instead of "let".

You also need modify your range a bit. The challenge wants you to log "the even numbers from 2 to 24".

Regarding the "let/var" issue, you might want to submit a bug report about it to the Support folks.