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

Rahim Spencer
Rahim Spencer
5,772 Points

Am I missing something?

Tried following along with the video, but can't seem to get this right. Can anyone see what i'm doing wrong?

var html = ''; 

for ( var i = 1; i <= 10; i += 1 ) {
  html += '<div>' + i + '</div>';
}
document.write(html);

Thanks! R

3 Answers

Hi Rahim,

Your code works as it is to print the numbers 1 through 10. You might be having some trouble with Workspaces. If you would like more resources to test your code, you can use JS Bin or the JavaScript console in Chrome Dev Tools.

I hope this helps, Alex

Rahim Spencer
Rahim Spencer
5,772 Points

Ohh I see. Was going crazy trying to figure out what was wrong. Thanks for taking a look!

Frank Ruiz
Frank Ruiz
15,558 Points

For anyone else having trouble, double check to make sure the file "script.js" matches the file in the "index.html" code.

marco berardini
marco berardini
3,393 Points

Had a similar issue when I created my script file (ctl clicking file JS )it actual was created in the main body of the program. Drag and drop file into js and everything works fine.