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

Ali Karukas
Ali Karukas
192 Points

It says to: Open an alert dialog with the message "Warning!" I placed: alert("Warning!"); Whats wrong?

It says to: Open an alert dialog with the message "Warning!"

I placed: alert("Warning!");

Into the index.html file and its saying I am wrong. Is there something I am missing?

Thanks! Ali

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>
document.write("<h1>Alert</h1>"); 
</body>
</html>

3 Answers

Hi Ali,

you COULD place the javascript code inline in the html. However then you must place the code WITHIN the script tags like so:

<!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>
    document.write("<h1>Alert</h1>"); 
  </script>
</body>
</html>

However placing javascript inline is considered bad practice. As your html code indicates, you are supposed to place the code inside the file scripts.js which is added to the html with the script tags:

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

Just open the file scripts.js and place your code in there and you should pass the challenge.

You're simply putting it in the wrong file. It should go in scripts.js, not index.html.

Remember that HTML is a markup language, not a programming language. HTML will create the static layout of the page; CSS will style that content; JavaScript will allow an application run on the client machine that manipulates the content displayed in the browser.

Each file serves a unique purpose, and it's important to remember which files get which kinds of code.

Ali Karukas
Ali Karukas
192 Points

Thank you everyone!

I'm also stuck on this challenge question and I don't see a way to create a separate .js file to run the script in. It only has the index.html file ... am I missing a way to add the .js file?