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

Christopher Flores
Christopher Flores
6,898 Points

Not sure what it needs me to do...

There's no scripts.ja tab... that's where I'd write * document.write("Welcome to my site"); * correct?

Within the <script> tag I wrote * scripts.js * to see if it would make that tag but it didn't show up in the preview.

I have an idea of what it wants me to do, just not how to do it with only an html tab.

pls 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>

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

</script>

</html>

4 Answers

You need to ensure the code has been entered in between the script starting and closing tags. As per below:

<!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.
document.write("Welcome to my site");
</script>

</html>
Ruben Ponce
seal-mask
.a{fill-rule:evenodd;}techdegree
Ruben Ponce
Full Stack JavaScript Techdegree Student 12,035 Points

We reserve the inside of the opening tags of HTML elements for these things called attributes. Like id="submit-button" and class="main-content". Your code doesn't work because the browser is trying to interpret the code as an attribute rather than a script. So all you need to do is put the code within the script tags. <script> //code here </script>

Christopher Flores
Christopher Flores
6,898 Points

Thanks guys

I suppose I was just overthinking it. And I wasn't aware you could write a JavaScript statement inside html the same way.

appreciate it

Habiballah Hezarehee
Habiballah Hezarehee
7,193 Points

The <script> tag is used to tell the browser you are going to use javascript, and then the browser will look for any javascript codes which are placed inside the <script> tag </script> to compile. Edit your code as follow: <script> document.write('Hello World'); </script>

But on the other hand you may be able to attach a js file to your index.html file by using the src attribute in your <script> tag as follow: <script src="file.js"></script> And then write your own code in the file.js file which can be also compiled correctly. For more info check out the developer.mozilla.org