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

I can not link the js file to the html. It won't show the popup message. When i write it in the html directly it works.

please help

5 Answers

this worked for me, take out JS/, so it should be "<script src="script.js"></script>". Im happy im starting with a free trial I just started these courses and I don't get why there is so many issues in the teachings and fellow students are the ones finding the answers to these problems. This comment from 2 years ago helped me, yet there isnt an edit in the video for a known issue?

josephweiss2
josephweiss2
7,094 Points

try to link the js file at the end of the html right before the </body> tag, it should work

tried everything, even i tried with the basic html example but still doesn't work.

josephweiss2
josephweiss2
7,094 Points

can you share the html and the js you want to link?

Hello, This message is for people who have the same problem as you. Because I believe that since August 2022, your problem has been resolved.

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>JavaScript Basics</title>
    <link href="css/style.css" rel="stylesheet">
  </head>
  <body>
    <main>
      <h1>Hello, JavaScript!</h1>
    </main>
    <script src="js/preview.js"></script>
  </body>
</html>

You must pay close attention to the path of your JavaScript script. If it is stored (as in the lesson) in a folder called "js," you need to go up one level in the hierarchy.

Alternatively, if it is stored at the same level as your HTML index file, use the example below.

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

@melanieelanduenas Tks very much. Now that you said ran out like supossed to. <script src="script.js"></script>