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

Melissa Rose
Melissa Rose
1,337 Points

Code is correct, but it is telling me that I'm not using the document.write statement

It is producing an error stating that I'm not using the document.write statement according to the requirements when I hit submit, but I am. I can't spot the error. Can any one help so that I can move past. Thanks

index.html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>JavaScript Basics</title>
 </head>
<body>
  <div class="container">
  <script src="scripts.js">
    document.write("<h2>Welcome to my site</h2>");
  </script>
  </div>
</body>
</html>
Gunhoo Yoon
Gunhoo Yoon
5,027 Points

I had to update my question because it addresses wrong problem so check it out.

1 Answer

Gunhoo Yoon
Gunhoo Yoon
5,027 Points

Update: Sorry but I made major mistake.

It is true that grader does check for syntax however your case turned out to be different. Can't believe I missed this.

Actual problem

<script src="scripts.js">

Because you explicitly included the source of file, the script will run in context of scripts.js. This means the browser has no interest in running codes inside the <script>. This means you need to choose between external script or internal script per script tag.

**You actually can use "<h2>Welcome to my site</h2>".

--------------------------------old-----------------------------------------

One of few disadvantage of solving online code challenge is that they expect you to write specifically what they've told you to do. It depends on type of problem but that's general idea around.

Like you know, your code has no problem and can be used in real life situation(although this is highly unlikable).

So, here is what grader asked, write "Welcome to my site" to your page using document.write() method.

But you did "<h2>Welcome to my site</h2>".

I don't want to say correct but what is correct for grader is this

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