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

Brent Cralley
18,541 PointsProblems linking JavaScript file to HTML file
Hey forum!
I'm having a lot of problems linking my JS file to my HTML file, and I can't figure out what's wrong.
I apologize in advance if my code doesn't post right. This is my first time asking a question on this forum....
This is just an excerpt from the bottom of my HTML code where the script tag is. I've verified(about 15 times) that the .js file name is spelled correctly and in the same folder as the HTML file.
<footer>
© BC Webinations 2014
</footer>
<script> src="calc.js"</script>
</body>
</html>
My JS is just a simple alert to let me know it's working, which it isn't...
alert("Help me!");
Now, I'm aware that I didn't declare a "type" in the script tags, and that's because every time I do, the javascript returns a syntax error.
I'm expecting it to be just a stupid little typo or something....
Thanks guys!
-Brent C.
P.S. I'm running the latest Google Chrome with Ubuntu, if that means anything.
7 Answers

Jeff Busch
19,287 PointsHi Brent,
Change:
<script> src="calc.js"</script>
To:
<script src="calc.js"></script>
Jeff

Ken Alger
Treehouse TeacherBrent;
You need to put your src
assignment inside your script tag. <script src="calc.js"></script>
should do the trick.
You can move it to a separate js
folder like Robert mentioned, that is a pretty common practice.
Happy coding, Ken

Robert Manolis
Treehouse Guest Teachernot sure, but try putting your js into it's own subfolder that sits next to your html file, name the subfolder simply js, and then you link like this, <script> src="js/calc.js"</script>
hope that helps

Brent Cralley
18,541 PointsGave your suggestion a shot, Robert, and still no dice. From what you can see, all of my syntax is correct, right?
-Brent C.

Brent Cralley
18,541 PointsThanks for the help, guys! I knew it had to be something stupid that I just wasn't seeing. ;-)
Now, on the plus side, my script tag now accepts "type="text/javascript" without showing any syntax errors.
On the downside, it's still not showing any of my javascript in either the console or a pop-up alert window....

Jeff Busch
19,287 PointsCopy and paste your code here.

Brent Cralley
18,541 Points <footer>
© BC Webinations 2014
</footer>
<script type="text/javascript" src="calc.js"></script>
</body>
</html>
alert("Help!");
console.log("Help me!");

Jeff Busch
19,287 PointsWith the code you have the html and javascript files must be in the same directory. Your code works on my computer.
Ken Alger
Treehouse TeacherKen Alger
Treehouse TeacherJeff;
I must have hit "Post answer" moments before...
Ken