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

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>