Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Basics (Retired) Introducing JavaScript Link to an External Script

Can someone explain inserting javascript into html to me please im confused.

just need a little explaination is all

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="shouts.js">
  <script src="shouts.js">
               <script>alert("Hey!");
  </script>
</body>
</html>
shout.js

2 Answers

Frank Browning
Frank Browning
4,274 Points

You are linking it correctly, however all tags need an ending tag. For example, to properly link the shouts.js you would need to do this

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

After that if you wish to add more scripts it would need to be between the two tags. The way you have it now, there is only one ending tag for three different scripts which would cause an error.

Frank Browning
Frank Browning
4,274 Points

When I say in-between the two tags I don't mean in between the shouts.js tags I mean new tags before or after that. Let me know if you can understand my ramblings.

Duncan Gossage
Duncan Gossage
3,196 Points
  <script>
    console.log('So you mean the other way is between script tags like this as well :-D');
  </script>