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 Hello, JavaScript! Debug JavaScript in the Console

Text not in the same position as the video

Hey I'm just wondering in my page the "Hello Java script" title from my html is being under my "welcome to my web page" from my javascript. I know its not much of a big deal but I still want to understand why it's doing this

This is my JavaScript code

alert("Hello world");
console.log("hello from the console");
alert("Thanks for visitting");
document.write("<h1>Welcome to my web page.</h1>");

Here is my HTML code

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>JavaScript Basics</title>
    <link href="css/style.css" rel="stylesheet">
    <script src =js/script.js></script>
  </head>
  <body>
    <main>
      <h1>Hello, JavaScript!</h1>
    </main>
  </body>
</html>

Thanks for the response

1 Answer

My best guess is that the instructor's index.html is a little different from yours. If you go into your index.html and move the <script src =js/script.js></script> line to the bottom of your file (somewhere before </html>), then it will execute after the "Hello Java Script" line, and therefore it will write it to the document after it, as you see in the video. Since your script is in the head, it is executing as soon as the page loads, before it gets a chance to process the body of the html, thus it shows up before "Hello JavaScript"