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

David Moody
David Moody
19,302 Points

I am putting a <script> tag inside the <body> tag, but the program is giving me an error.

Do I need to add "src=" to my <script> tags.

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

  <script>document.write("Hello")</script>
  <script></script>
</body>
</html>

5 Answers

The reason that it's giving you an error is because you missed a semi-colon at the end of your document.write() function. It should look like this: <script>document.write("Hello!");</script>

Hope this helped!

Stephen Urena
Stephen Urena
705 Points

I guess it depends on what the error says, but it looks like you capitalized "Content-type", should be like this

<meta http-equiv="content-type" content="text/html; charset=UTF-8">
David Moody
David Moody
19,302 Points

The error is that it is testing to see if I am putting a <script> tag in the <body> section. It keeps saying that I am not inserting any <script> tags in the <body> section and won't let me pass that challenge in the class.

Did you try to put the semi-colon after the document.write? When I did that it let me pass through no issues.

Stephen Urena
Stephen Urena
705 Points

Ahh ok, well for one you should delete the extra <script> tags in your head, and the empty one below...document.write()...so your code should look something like...

<!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("Welcome to my site");

</script>

</html>

I said that in my original answer...

Rohit Ukirde
Rohit Ukirde
10,453 Points
<!DOCTYPE HTML>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>JavaScript Basics</title>
</head>
<body>
  <script>document.write('Hello');</script>
</body>
</html>

This Works fine