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 For Loops

Heather Scroggins
Heather Scroggins
30 Points

<div>s not showing up in page preview.

I've looked through the rest of the questions and triple checked my code, but I can't find what I'm doing wrong. My code looks like it should work but for some reason, the numbered <div>s are not showing up when the page is previewed.

Here is my code:

var html = '';

for (var i = 0; i <= 10; i++) {
  html += '<div>' + i + '</div>';
}

It looks to be the same as the code in the video but I can't get it to work. Any and all suggestions would be greatly appreciated. And yes...it is linked correctly in my HTML doc because I've been using the same workspace for this entire course and all other code before has worked.

2 Answers

Jesse Zelaya
Jesse Zelaya
13,598 Points

Are you printing your results to the document as well?

document.write(html)
Heather Scroggins
Heather Scroggins
30 Points

Oh my goodness. No, actually, I wasn't. Argh! I spent a good half hour trying to figure out why it wasn't showing. It never occurred to me that there was no document.write statement.

Thanks!