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

3 Answers

andren
andren
28,558 Points

When you declare the for loop you are missing the i variable in your comparison. It's meant to be i <= 100 you just have <= 100.

If you add the i like this:

var html = '';

for (var i =1; i <= 100; i +=1 ) { // Added "i" to the comparison (middle) step
  html += '<div>' + i + '</div>';
}
document.write(html);

Then your code will work.

I've tried several versions of code and I'm not getting it to work. Including the answer above!

Justin Houghton
Justin Houghton
4,560 Points

I had the same issue - my issue was that when I created the script.js file, I didn't put it within the js folder. I just right clicked and created a new folder.

Once I dragged the file into the js folder, the link on the index page worked and I was able to preview the divs.