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 trialSamantha North
9,450 PointsDivs not showing up
Hi there everyone. My divs don't show up on the page, even though I think my code matches the video. Can anyone help? Here's my code:
var html = ' ';
for (var i = 1; i <= 10; i += 1) { html += '<div>' + i + '</div>';
} document.write(html);
11 Answers
Paul Allen
8,484 PointsSamantha, I've just been sitting here beating myself up, having the exact issue you had. Finally, I downloaded the Workspace file and ran the code outside of Workspace, it worked just as it should. I don't know whether it's a glitch/setting in our local machines, or one with Treehouse/Workspaces, but what I have taken away from the last 45 minutes of time wasted... if after going over your "non-working" code once and all seems ok, pull and run the code elsewhere outside of here to know for certain it's truly broken code, or just whatever this glitch is that sometimes keeps good code from running in Workspaces. For the record... I did save my work and restart Workspaces (and ALL browser windows, as well as a complete machine reboot) several times, didn't make a difference, code still wouldn't run properly until I got it away from Workspaces.
Valentin Fezza
18,178 PointsSamantha,
I tried running your first and second pieces of code and both fired A-OK on my browser. I was having a similar problem until I tried writing the <script> tag again. Not sure why, after writing down the exact same thing, the code ran without a hitch.
I know you're 100% sure script.js is inside the js folder. However, I'd really like for you to check one last time. All new files are created in the root folder, so you'd have to drag script.js into the js folder for it to actually be there. This is often overlooked, especially because the workspaces UI can make you think new files are inside one of the top folders when they're really not.
If it looks like both index.html and script.js are at the same level of indentation in the file explorer, give this a go. Then relaunch workspaces. All the best!
Carlos Federico Puebla Larregle
21,074 PointsNope, I can't find any bug. I copy and pasted your code into mine and it worked so the only thing I can think of is that your script.js file might be in the wrong place.
Samantha North
9,450 PointsI've checked again and the file is definitely inside the js folder. I'll try reloading the workspace; as perhaps it's a glitch with that. Thanks for helping me out.
ericafanelle
1,225 PointsI'm having the same trouble. My code looks identical to yours and Dave's, yet it still won't run. I'm stuck!
Darrell Conklin
Python Development Techdegree Student 22,377 PointsI was having the same issue until I took the code outside of workspaces and pasted into a code editor (currently using Brackets) and found a lot of errors. Revised the code to:
var html = '';
var i;
for (i = 1; i <= 10; i += 1) {
html += '<div>' + i + '</div>';
}
document.write(html);
pasted it back into WorkSpaces and everything worked fine.
Mike LaPan
5,190 PointsI took the code outside of Workspaces, and it works fine. Inside of Workspaces it does not. This shouldn't be the case, but it is. This should be flagged for Treehouse to look into.
Very odd behavior... and super frustrating if you are trying to learn. :-)
Carlos Federico Puebla Larregle
21,074 PointsRemember to put your script tag inside of your body tag in the index.html file.
<script src="js/script.js"></script>
This is my code for the "script.js" file:
var html = '';
for ( var i = 1; i <= 10; i += 1) {
html += '<div>' + i + '</div>';
}
document.write(html);
I hope that helps a little bit.
Samantha North
9,450 PointsHey Carlos, thanks for your reply. I've checked and re-checked the script tags and everything looks exactly the same as yours and Dave's. The js file is in the correct place inside the js folder. But there's still nothing showing up in the browser... Am I missing anything else that you can think of?
Carlos Federico Puebla Larregle
21,074 PointsCould you post (copy and paste) your code so I can see if I find some error?
https://teamtreehouse.com/community/posting-code-to-the-forum
In that link it explains you how to do it properly.
Samantha North
9,450 PointsOK, here's my html first:
<!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>
and my JavaScript:
var html = ' ';
for (var i = 1; i <= 10; i += 1) {
html += '<div>' + i + '</div>';
}
document.write(html);
Darrell Conklin
Python Development Techdegree Student 22,377 PointsUsing Mozilla Firefox Developer Edition eliminated the issues I was having with code not working in workspaces
Derek Wagner
Courses Plus Student 1,413 PointsAfter you add the script tag to the index.html make sure that you save that file. After saving index.html and script.js it worked for me.
Mike LaPan
5,190 PointsMike LaPan
5,190 PointsYup, same thing here.