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 Write Another Program

Unsure of where to put alert function

Please help. I am stuck

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="script.js"> alert
    alert("Warning!")
  </script>

</body>
</html>

1 Answer

Unsure as to what you mean by where to put it...It will work just fine inside the script tag that you have.

However there is a problem with your code. You cannot create a script tag and give it an attribute of src and then put code inside the script tags...that just does not work.

Incorrect

<script src="script.js"> alert
    alert("Warning!")
</script>

Correct

<script>
    alert("Warning!");
</script>

<script src='script.js'></script>

also, you added an extra "alert" to the code that should not be there. And you missed the ; at the end of your alert statement. While javascript is forgiving about this sort of thing it is best practice to include it at the end of most lines.

hope this helps.

Thank you so much! I now can see where I made the mistake. Thank you!