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

Sneha Mondal
Sneha Mondal
219 Points

Add code inside the <script> tags to write the words "Welcome to my site" onto the web page.

I wrote the below script: document.write("<h1>Welcome to my site</h1>"); But it is showing the error " you didn't call document.write function." Please help.

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>");>
// Write your code here.

</script>

</html>
Sushant Kumar
Sushant Kumar
Courses Plus Student 3,555 Points

Hi Sneha, Please write code in <script> tag, and also try to write script in Body. document.write should not be in corner bracket "<>".

Code should be:

<!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>');
     // Write your code here.
</script>
</body>
</html>```
Marc Maninang
Marc Maninang
1,147 Points

In order for Javascript to run in HTML, it needs to be wrapped in script tags: <script> </script>

Looks like you're missing the opening script tag.

1 Answer

Steven Parker
Steven Parker
229,787 Points

Right code, wrong place!

  • your code needs to go between the script tags
  • it looks like you replaced the first tag with your code instead
  • a blank line was left after the comment where you should put your code
  • never alter code given in a challenge unless the instructions specifically say to
<script>
// Write your code here.
document.write("<h1>Welcome to my site</h1>");
</script>