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

Alexander Melo
Alexander Melo
4,297 Points

Nothing is happening...

When i write the javascript nothing happens. I double checked everything there is no console error and any error on the html. Can someone help me out here?

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Circles</title>
  <link rel="stylesheet" href="css/styles.css">
</head>
<body id="color">
<script src="js/script.js"></script>
</body>
</html>
var html = '';

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

4 Answers

Samuel Steed
Samuel Steed
2,568 Points

I had the same issue with this workspace. I checked the console and was getting an error loading the script.js file. It finally resolved after I moved the script.js file out of the js folder and changed the reference from

<script src="js/script.js"></script>

to

<script src="script.js"></script>

...not sure what's up with that folder as it seemed to be working for Dave.

Lanie Williamson
Lanie Williamson
Courses Plus Student 11,390 Points

I also had this problem and checked several forum links and this was what finally helped. Thanks Samuel!

Hey Alexander, So if you want to see your output in the console, you need to:

console.log(html);

Otherwise, you're just creating a variable and not doing anything with it.

Alexander Melo
Alexander Melo
4,297 Points

This is exactly how Dave wrote it in the video and numbers appeared with a light gray circle around it and when i preview nothing appears but thanks I will try to console.log it.

I had this exact same problem. Try saving it in html and in the javascript file and then preview it. This finallly worked for me.

Ben Rawlins
Ben Rawlins
9,093 Points

You are forgetting to add document.write(html) after the for loop.