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 trial

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

Can someone help me with this for loop?

I am trying to refactor but it's not working. What am I doing wrong?

script.js
``` javascript
var console.log;

for (var i = 2; i <= 24; i += 2) {
  console.log(i);
```index.html
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JavaScript Loops</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>

2 Answers

Josh Sneddon
Josh Sneddon
15,943 Points

Hi Michael, your for loop is fine apart from the missing closing bracket. You're just overcomplicating the challenge by trying to create a variable for console.log. Delete that, add the closing bracket to the for loop and you'll pass.

For your information, the variable name you have defined is invalid because console.log is already part of the JavaScript language. Bear that rule in mind going forward.

There is no need to create console.log variable. Console.log() is a function and I'm not sure whether you can even use it as a variable name.