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

What I'm doing wrong, because if test this code in workspace it works perfectly, but for some reason I get a bummer

What I'm doing wrong, because if test this code in workspace it works perfectly, but for some reason I get a bummer:

"You need to log out EVERY number from 4 to 156 to the console. Your loop calls the console.log() method 1 times."

script.js
var a = '';

for (var i = 4; i <= 156; i += 1) {
  a += '<div>' + i + '</div>';
}
console.log(a);

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! Check closely what it says again:

You need to log out EVERY number from 4 to 156 to the console. Your loop calls the console.log() method 1 times.

You are building up a string and then logging out that entire string to the console. But the challenge is asking for you to call the console.log() inside the loop. It also says nothing of creating any HTML elements. The point is that you're doing a bunch of things that are functional, but not was asked of the challenge. You've added a lot of extra things that aren't required.

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

:bulb: Going forward, try not to do anything that's not explicitly asked for by the challenge. Even if functional, it can cause the challenge to fail.

Hope this helps! :sparkles: