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 Functions Pass Information Into Functions Variable Scope

Daniela Fernandes Smith
PLUS
Daniela Fernandes Smith
Courses Plus Student 10,353 Points

When I test this code on Google Chrome, it doesn't load the page before the alerts pop up

When I test this code on Google Chrome, it doesn't load the page before the alerts pop up, even though the JavaScript file is at the end of the body tag. Is this normal behavior? How can I get around it and have the page loaded before the alerts pop up?

Thank you!

1 Answer

Temitope Ogunleye
seal-mask
.a{fill-rule:evenodd;}techdegree
Temitope Ogunleye
Full Stack JavaScript Techdegree Student 2,186 Points

Try to put JavaScript <script> tags just before the closing </body> tag like below, The reason is because HTML loads from top to bottom:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>JavaScript Functions</title>
    <link href="css/style.css" rel="stylesheet"> 
  </head>
  <body>
    <main>
      <input type="text" id="info" value="My info">
    </main>
    <script src="js/scope.js"></script>
  </body>
</html>