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 Create a for Loop

david mchale
david mchale
1,434 Points

For Loop Quiz problem

Cant figure out why its telling me i need to log the numbers to the console when ive done the exercise in my browser and it works...

var myVar = "";

for(var i = 4; i <= 156; i++){

myVar += "<div>" + i + "</div>";

}

console.log(myVar);

5 Answers

Steven Parker
Steven Parker
229,744 Points

:warning: Be careful about testing a challenge in an external REPL, workspace, or browser.

If you have misunderstood the challenge, it's also very likely that you will misinterpret the results.

In this case, the challenge is expecting you to call console.log from inside the loop, once for each number.

You also won't need any HTML tags, just log the number.

Shawn Rieger
Shawn Rieger
9,916 Points

Are you sure it's not looking for...

for( var i = 4; i <= 156; i++) {
  console.log(i);
}

When doing what you've posted in your browser, while it works, it's not printing the numbers themselves to the console. It's printing a string variable with each number wrapped in it's own div container.

david mchale
david mchale
1,434 Points

Thanks guys! All good.

Nick Pirini
Nick Pirini
4,186 Points

The following runs using atom but not is not accepted as an answer in the code challenge (create a loop that numbers...). feeling quite annoyed. var counter = 0

for (var counter = 4; counter<=156; counter +=1 ) { console.log(" " + counter + " "); } Sincerely, what am I missing?

Steven Parker
Steven Parker
229,744 Points

You're not exactly "missing" anything. But those extra spaces you are wrapping your values in are confusing the checking mechanism. You don't need them anyway, since log messages will each appear on a separate line.

As I told David, "just log the number".