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

Brijen Patel
Brijen Patel
74 Points

why is it wrong

can u help me

index.html
<!DOCTYPE HTML>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>JavaScript Basics</title>
</head>
<body>
 alert("Hello World");

</body>
 alert("Hello World");
</html>

3 Answers

Justin Radcliffe
Justin Radcliffe
18,987 Points

Hi Brigen,

Firstly, you need to include JavaScript inside script tags:

<script></script>

And secondly, the challenge asks you to log "Warning" and not "Hello World". I hope these pointers will help you a bit. If you have any further dificulty let us know.

Charles Kenney
Charles Kenney
15,604 Points

Brijen,

I'm going to walk you through the steps of this code challenge and explain how it works.

The first thing we need to do is write an opening and closing set of script (<script>) tags inside the body tag. Your markup should look like this:

<!DOCTYPE HTML>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JavaScript Basics</title>
  </head>
  <body>

    <script>

    </script>

  </body>
</html>

Then we need to open an alert dialog with the string 'Warning!'. We can do this by calling the Window's alert method and passing the string "Warning!" as a single parameter. Your code should look something like this.

<!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>

Hope this helps

-Charles

Hi there. JavaScript should be incorporated within

<script> /*code goes here*/ </script>

when injected directly into HTML.

You might also find it helpful to create a separate js file to edit and then link to in your markup,

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

and then editing your javascript from a separate file. Hope this clarifies!