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 Basics Hello, JavaScript! Add JavaScript to HTML

My script source JavaScript is not working even with the same code as the teacher.

In the test website, I do not get a popup from scirpt.js. Here is my code:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>JavaScript Basics</title> <link href="css/style.css" rel="stylesheet"> <script src="js/script.js"></script> </head> <body> <main> <h1>Hello, JavaScript!</h1> </main> </body> </html>

For the JavaScript, I have this: alert("Hey, you're back for more!");

5 Answers

When I had this problem it was because I hadn't saved BOTH the script.js file and the index file. You can't save once for both files, you need to click save on each one separately.

Simon Coates
Simon Coates
8,177 Points

I copied your code and ran it on my desktop. It worked fine. If you're using workspaces, do you know how to create a snapshot and post a link to it so people can debug a copy? Like I said, your code worked fine. So the basic things to check are the silly things like making sure you saved, checking the directory structure matches the location specified in the src attribute of the script tag, and verifying via the browser tools that there wasn't an error. Console would print some output if there was an error with your javascript. The network tab can be used to verify that the .js file is able to be found. at all.

HI Julie,

You might have placed the script.js file incorrectly. It must go inside the JS folder.

terry okey
terry okey
3,187 Points

Thanks, it was so NOT obvious that I hadn't had the cursor in the right place when I added a new file.

Hi there,

I'm running into the same issue as mentioned by Julie.. I checked to make sure the script.js file was in the correct folder and double-checked all of my code against Guil's. I also made sure each file was saved.

Here is a snapshot of my workspace. https://w.trhou.se/jbawe4gz60

Any thoughts?

Simon Coates
Simon Coates
8,177 Points

I think it worked fine (based on your snapshot) after I added in the missing quotation mark in script.js

alert("Hey, you're back for more?");

I assume two alert messages was expected behavior.

Hello, I had this problem as well, it seems if you accidentally place the "index.html" file in either the "js" file or "css" file they return a webpage with two folders and a white background webpage. The "index.html" file should be in the JavaScript Basics file(outside of both the js and css files.