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 Your First JavaScript Program

document.write (<h1>"Welcome to my site."</h1>); this is what i am writing but it is not coming out correct.

Im not sure what I am doing wrong but it is not correct.

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

<body>
</body>

  document.write(<h1>"Welcome to my site."</h1>);


</html>

3 Answers

Jeff Jacobson-Swartfager
Jeff Jacobson-Swartfager
15,419 Points

You'll need to do a couple of things to get this functioning:

  1. Place your javascript within script tags or load a file
  2. Wrap your entire string in quotes

You can find out more about the script tag on MDN. With html5, the browser assumes the contents within the script tag is javascript. You could add a type attribute of text/javascript if you wanted. You'll want to include this either within the head element or within the body element. Right now, you've got it after the body element.

You probably intend to write an h1 element with the contents of "Welcome to my site." To your page. This is an complete string that you'd need to provide to document.write.

All together, it will probably 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>
          document.write("<h1>Welcome to my site.</h1>"); // The entire string needs to be quoted, not just the contents of the html element
      </script>

    </body>
    </html>

Hi Mark,

document.write() function needs to be wrapped by script tags, and the h1 tag needs to be inside the quotes.

<script>document.write("<h1>Welcome to my site.</h1>");</script>

Best Regards

Chris Shaw
Chris Shaw
26,676 Points

Hi Mark,

Not sure why you have an H1 tag wrapping your string but it doesn't need to be there, simply remove it so you have the following, you also don't need the period/full stop at the end of the word site.

document.write("Welcome to my site");

Happy coding!