JavaScript JavaScript Basics Hello, JavaScript! Add JavaScript to HTML

Julie Miller
Julie Miller
191 Points

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

Joanna Conrad
Joanna Conrad
1,192 Points

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
4,078 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.

Melissa Ellis
Melissa Ellis
6,717 Points

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
4,078 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.