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

Paul Henry
Paul Henry
2,125 Points

Copied code exactly and nothing shows up

I checked to make sure the src is correct in the html file, and copied Dave's code exactly. When I hit preview, nothing shows up on the page. I see other people have had this problem, but I haven't seen a solution offered yet.

var html = ' ';

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

5 Answers

Anthony Scott
PLUS
Anthony Scott
Courses Plus Student 9,001 Points

mine wasn't running because I forgot the = between script and "script.js in the html file.... and it was giving me no error in the console so it was confusing at first.

I have tried all the suggestions above...

<!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 += 10;) {
  html =+ '<div>' + i + '</div>';


}
document.write(html);

the issue has not been resolved. I do not see the results

I'm kinda just shaking my head and raising my right eyebrow... I think you knew that there was no list in the HTML...

Try pressing Cmmd+Shift-i on a Mac when viewing the result or Ctrl+Shift+i on Windows while seeing the result.

What do you see in the Console?

Paul Henry
Paul Henry
2,125 Points

Nothing shows up in the Console at all... It's weird because in a later exercise using the colored circles, it works just fine.

Roshini Thiagarajan
Roshini Thiagarajan
8,941 Points

Try to do an inspect element on the page that opens up upon 'Preview'. There are also chances when copy-pasting code that characters are not represented as required for example ' ' ' maybe represented with another ASCII character.

Isaac Kim
Isaac Kim
1,379 Points

It may have something to do with adding the src.

In the video he tells you to put: <script src="js/script.js"></script>

but if you take "js" our (so just: <script src="script.js"></script>), it works correctly. Hopefully that helps, not sure why adding the "js" to guide it isn't working correctly.

depends on where you saved the file. If you save it inside a folder called "js", then the instructions in Dave's video work.

if you don't save it inside a folder called "js" but instead create the file in the same place as your html, then you don't need to add the js folder to your path. you can use "script.js" and it should work.

Thank you Anthony Scott, I pursued the next exercises and found the same problem. I ventured into the HTML. There was no <ol> <li></li> </ol> to begin with.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Musical Playlist</title>
  <link rel="stylesheet" href="css/styles.css">
</head>
<body>
<h1>My Music Playlist</h1>
<script src="js/playlist.js"></script>

</body>
</html>

I'm confident that this was the issue. at least with "My Music Play List Lesson" I figured this out. I'll see if the =+ , =+ makes a difference and thanks again!