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
John Shields
7,477 PointsI don't know what I'm doing wrong. None of my javascript ever seems to work.
Here is my code. I copied it directly from the video. Nothing prints to the screen. This happens ever single time I try to follow along with these javascript videos. I can't ever get any of them to work!
var html = '';
for ( var i = 1; i <= 10; i += 1 ) {
html += '<div>' + i + '</div>';
}
document.write(html);
9 Answers
Konrad Pilch
2,435 PointsDid you linked the script to your HTML?
John Shields
7,477 PointsI typed it in workspaces and hit the preview button. Nothing. I did link the script.
Neil Anuskiewicz
11,007 PointsJohn, maybe you could post your HTML just in case there's something there that could be causing it. You never know.
John Shields
7,477 Points<!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>
Neil Anuskiewicz
11,007 PointsDoes the HTML load other than the JavaScript? That is, maybe put <p>Hello</p> in there and make sure that your HTML is rendering. It might not be the JavaScript that's the problem.
John Shields
7,477 PointsOk I did that and the HTML works fine.
Neil Anuskiewicz
11,007 PointsThe file called script.js is in a directory called js? And the index.html is this relationship to where the file lives js/script.js?
I've seen even the instructors put JavaScript up a directory from where they intended, an easy mistake to make. I ran your JavaScript using Chrome's console and it worked. You verified that the HTML renders. So I think what's left is it's not finding the script itself for some reason.
John Shields
7,477 PointsIDk. This has happened pretty much every time I've tried to follow these lessons. It's to the point where I'm not learning and just trying to figure out what's wrong.
Neil Anuskiewicz
11,007 PointsWhat class is it? I'll see if I can fire up the workspaces console and run your HTML and JavaScript. Don't let stuff like this get you discouraged as frankly hassles are just part of the tech world. I work in tech in a non dev role but nonetheless hassles are part of daily life at a software company. So, what class is it, what lesson, what browser are you using, and what OS?
Neil Anuskiewicz
11,007 PointsBTW, I expect we can find the cause of this problem as it's probably the same cause in each course that's causing this. Resolve that and you should be good to go.
Seth Kroger
56,416 PointsCan you take a snapshot of your workspace and post the link here. It's the icon in the upper-right that looks like a camera (or suitcase).
John Shields
7,477 PointsI seem to have figured it out. Neil, you are correct sir. When I created the .js file I neglected to place in the js folder. Feeling really dumb right now. haha
Neil Anuskiewicz
11,007 PointsThat's a super common error that literally everyone makes.
John Shields
7,477 PointsThanks everyone by the way!
Neil Anuskiewicz
11,007 PointsNeil Anuskiewicz
11,007 PointsI just ran your code in Chrome's console and it worked fine returning the output in the browser winidow. How specifically are you trying to run it?