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

Writing a JS script

Hi, I have a question of:

Inside the script tags, write a function that will open an alert dialog with the message 'Warning!'

My answer is this that I got directly from the video, but I got it wrong. Can anyone tell me what I have wrong in the JS/html?

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

Thank you so much!

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

3 Answers

Matthew Long
Matthew Long
28,407 Points

You're close. You tried linking to an external script file scripts.js. You also forgot to close the tag. You have to close the script tag: <script></script>. You can either add the source attribute, src inside the opening script tag to link to an external JavaScript file or you can write JavaScript directly between the opening and closing script tags. That is what this challenge is wanting:

<!DOCTYPE HTML>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>JavaScript Basics</title>
</head>
<body>
  <script>
    alert("Warning!");
  </script>
</body>
</html>
Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,858 Points

Matthew is correct, and the Community is exactly the right place to come when you have a question or are stuck.

Now... just something to remember with the the challenges is that they are meant to test the knowledge of the subject matter the videos go over. However, the challenges almost never exactly match the code in the video or workspaces, so copy/pasting often will not work.
The concepts will be the same, but the coding or naming or structure will more often than not be just a bit different. This way one has to hand-code the challenge based on the instructions provided (which are always very specific) and not just copy from the video or workspaces.

I glad you came to the Treehouse Community. I hope you enjoy the rest of the courses and challenges! :smiley:

:dizzy:

Well I surely didn’t think I could copy and paste an answer from the video, but thanks!