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

removing redundant code - 2-24 in the loops, arrays, and functions section. HELP! I'm totally stuck on this.

This is what I come up with and it seems like it works but it says it takes too long to run.

Any thoughts?

for (var counter = 2; counter < 26; counter + 2) {


This is trying to convert a series of numbers printed from 2-24 from the redundant console.log(2); console.log(4); console.log(6); etc,

to a single command that does the same thing.

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

2 Answers

Gergely Bocz
Gergely Bocz
14,218 Points

Hi Jeremy!

There are 2 mistakes:

  • First there is a problem with your for loop. At the end you should write counter += 2 (which is a short form for counter = counter + 2) and not just counter + 2.

  • The second problem is that you don't tell the for loop what to do, what to execute in the {}, you haven't written anything inside them, so there is no code to execute! This is the reason why the interpretes says it takes too long. You have to give the command to log the numbers to the console! Try doing it with your defined variable.

Good luck!

Thanks for the help! I switched the += and added the console.log() in the {}. Finally got passed this.