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

I stay I'm logging 154 times?

I'm stuck.

var html = ''; 

for ( var i = 3; i <= 156; i += 1) {
   html += '<div>' + i + '</div>'; 

2 Answers

console.log(html); // <- put this line below the last brace which will put it outside of the loop. Right now your building a large output variable but since the console.log is inside the for loop it keeps logging to the console.

such as:

<div>3</div> <div>3</div><div>4</div> <div>3</div><div>4</div><div>5</div> <div>3</div><div>4</div><div>5</div><div>6</div> etc...

I was just getting ready to leave work so I didn't have time to look over the challenge. I took at a look and it's wanting a very basic response. I put the solution below but I feel we should go over some of the issues. Your original code has the var in the right spot. Your parsing error was likely coming from the 2nd var in you for statement. It actually wanted you to log out every number from 4 to 156 but you were doing 3 to 154 and most importantly they didn't want the html <div> tags. Please feel free to ask additional questions and keep up the good work.

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

var html = '';

for (var i = 3; var <= 154; i+= 1) { html += '<div>' + i + '</div>'; } console.log(html);

Now it's just giving me a parse error