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
Tammy Burke
9,720 Pointslink to javascript listed incorrectly every time
Hi folks. I have created the two files in Sublime text, linked the js file as described, and when I open the html file it always tells me it cannot locate js file and it lists a file that says file:///Users/Tammy/Documents/programming/text/javascript
instead of file:///Users/Tammy/Documents/programming/text/myscript.js
Why is this happening? Because of it, I have not been able to follow along exactly. I have typed in new js in the provided area, and that will work.
But why is my link not working?
Thank you,Tammy
3 Answers
Tammy Burke
9,720 PointsHi Samuel,
- The files are in the same folder, "programming"
- This is my latest incarnation of linking the files:
<!DOCTYPEnhtml>
<html>
<head>
<title> Introduction to Programming</title>
<style>
html {
background: #fafafa;
font-family: sans-serif;
}
</style>
<script src="programming/text/myscript.js"></script>
</head>
<body>
<h1>Introduction to Programming</h1>
<h2>with JavaScript</h2>
</body>
</html>
I added the /text/ part because each time I tried to load it, the path had the word text in it looking for the file. Originally I just had the js file name since the are in the same folder.
- This is with the Intro to Programming track.
Samuel Webb
25,370 PointsI'm not understanding point #2. The <!DOCTYPE html> line is just to tell the browser that you're using HTML5. You should be linking the Javascript file right before the closing body tag. Doing it there lets all the HTML load before loading the JS. The bottom of you file should look something like this:
<footer>
<content></content>
</footer>
<script src="myscript.js"></script>
</body>
</html>
Samuel Webb
25,370 PointsSometimes you'll see script tags with the type attribute as well. But as of HTML5 this is not necessary since the default type of a script tag is Javascript.
Tammy Burke
9,720 PointsHI Samuel, This is how the Treehouse tutorial instructed to do it, in the head or header, I can't remember which now ... I just realized that the code did not show up as I had thought. Tricky!
Samuel Webb
25,370 PointsSamuel Webb
25,370 PointsI've got a few questions for you.
Where is your myscript.js file in relation to the html file you're linking it to?
In your HTML file, how are you actually linking it?
What video are you watching?
Not so much a question, but a suggestion. Make sure you learn about absolute and relative file paths.