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

Jorge Aceves
Jorge Aceves
533 Points

do not understand question

add code inside script

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

</script>

</html>

2 Answers

The challenge asks you to write code inside the <script> tags to write the words "Welcome to my site" onto the web page. Remember that to add javaScript code to a webpage you can do it in several ways; you can create an external file and then link to it in the head of your webpage; let's say that you have your javascript file in the same file level than your html file, you would then link to it like this:

<head>
  <title>JavaScript Basics</title>
  <script src="main.js"></script>
</head>

Now let's say that you don't actually want to create an external file but instead you want to write the javaScript code inside your html file, to do that you type in the script opening and closing tag and then instead of linking to an external file you actually write the code inside of the script tags like this:

<script>
  var string = "some text";
  console.log(string);
</script>

So, knowing all of this, in this case what you're being asked is to write your javaScript code inside of your script tags, just like the second case I just showed you. Then you're being asked to write the code that will write the words "Welcome to my site" onto the webpage, to do that you use the function document.write() it will accept some string as an argument and will print the result into the page. So to pass your challenge you type this

<body>
</body>

<script>
// Write your code here.
document.write("Welcome to my site");
</script>

You have to write the full text within quotes, otherwise it isn't a string. I really made this answer too long but, this is the kind of response I would had liked someone to give me when I was just learning.

Thanks so much I needed this answer as well. I truly didn't understand how to put document.write using script