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 trialHolly Williford
4,745 PointsI stay I'm logging 154 times?
I'm stuck.
var html = '';
for ( var i = 3; i <= 156; i += 1) {
html += '<div>' + i + '</div>';
console.log(html);
}
2 Answers
Edward Ries
7,388 Pointsconsole.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...
Holly Williford
4,745 Pointsvar 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
Edward Ries
7,388 PointsEdward Ries
7,388 PointsI 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); }