Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Basics (Retired) Introducing JavaScript Your First JavaScript Program

Zander Curtis
Zander Curtis
10,634 Points

Where is the place to add the script.js code?

Don't I have to write the document.write() code in a .js file?

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

<body>
</body>
  <div class="container">
  <script> src="scripts.js">"Welcome to my site"</script>
  </div>
</html>

4 Answers

Bart Bruneel
Bart Bruneel
27,211 Points

Hello Zander,

The script is on the right place in the html-document, but you have to place the src-attribute inside the script-tag. Like this:

<script src='scripts.js'></script>
Zander Curtis
Zander Curtis
10,634 Points

Thanks Bart,

Once I watched the next video I figured out it was supposed to be

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

That gave the right answer. Would your script work as well?

ZC

Bart Bruneel
Bart Bruneel
27,211 Points

Yes, if you would place

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

into a separate .js-file. So you can place it directly into the html-file by placing it in between the script-tags or you can place it in a separate .js-file by adding a src referring to the .js-file inside the script-tag.

Zander Curtis
Zander Curtis
10,634 Points

Thanks Bart for you help and your contribution to the Treehouse Community!