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

Kelsey Donegan
Kelsey Donegan
3,342 Points

Why is my script not executing the "back for more?" prompt from 3:45 of the video?

I've made sure to save both files, make sure the file name is exactly the same regarding spelling/capitalization/etc., and nestled the script.js file into JS. When I refresh the browser, no alert pops up. Any ideas? Additionally, running the second alert "another message from..." does work. Not sure why the src link isn't working.

Here's my code for reference.

<!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>

and the script.js code:

alert{"hey, you're back for more?");

1 Answer

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,252 Points

Try adding your code that references the script file, so that is the last element before the closing body tag.

Like this.

...
    <script src="js/script.js"></script>
   </body>

It could be that it's trying to perform the alert without knowing about the rest of the html file.

By doing it this way the browser will have loaded all of the HTML.

Also be sure that the script file is located in a js folder relative to the location of your html file. :-)

Kelsey Donegan
Kelsey Donegan
3,342 Points

I'm a fool. I was trying everything, even disabled by ad blocker to be extra about it then went back to the script.js file and realized I had a bracket instead of the first parenthesis. Thank you!

I tried doing this, but for some reason, it still won't work. Is it just a browser issue then?