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 (Retired) Introducing JavaScript Link to an External Script

How do you do it!

Looks like you haven't added a src attribute to the script tag. How do you do it

index.html
<!DOCTYPE HTML>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>JavaScript Basics</title>
</head>
<body>
<script> src="index.html" </script>
</body>
</html>
shout.js
alert("Hi");

2 Answers

Michael Hulet
Michael Hulet
47,912 Points

You're close. <script> may not be self-closing when linking an external file, but all that should ever go between its opening and closing tag is JavaScript that should be executed. Instead, to link an external file, you use an HTML attribute. You're mostly right, but attributes go inside the opening tag in HTML, like the href in <a href="example.com"></a>. Likewise, you'll need to link to a JavaScript file in your script tag. Based on your answer, the file you probably want is shout.js

so it is <script src="index.html"> </script>

Michael Hulet
Michael Hulet
47,912 Points

That's better, but you're specifying the wrong file. You're in the HTML file, and you need to tell it about the JavaScript file with the <script> tag. The file you want is called shout.js