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

Allan Leiboh
Allan Leiboh
83 Points

I having trouble figuring out where I'm supposed to put the document.write function in challenge task 1 of 1

...

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

<body>
</body>

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

</script>

</html>

2 Answers

Stuart Wright
Stuart Wright
41,120 Points

You need to fix three things:

  • Remove the // from the start of the line. That means the line is a comment, so doesn't get executed.
  • Remove the <h1> tags from inside your string. "Welcome to my site" is all you need in the string.
  • JavaScript is case sensitive. The write method belongs to document, not Document.
Matthew Lang
Matthew Lang
13,483 Points

Hey!

JavaScript code can be put either inside <script></script> tags on the HTML document or in an external file which is linked to the HTML document via <script src='fileName'></script> tags. The method you are using is the first one, which is completely fine.

I believe the reason you are experiencing an issue is because you have the characters '//' in front of your line of code. These characters 'comment' out any code following them on the same line, which basically makes them invisible to the JavaScript interpreter. Remove these characters, and all should work!

Example:

<script>

// This is a comment, and won't be seen or even acknowledged!
//Document.write("<h1>Welcome to my site<h1>"); This is also a comment, so the code won't be run!

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

</script>