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! JavaScript Practice Challenge

Jezz Rose
Jezz Rose
2,177 Points

Hello, javascript message not showing

My alert boxes and boom message as well as the console message works just fine but the original hello javascript message doesn't appear initially.

When I comment out the alerts etc it shows up.

What am I missing? Why do the alert boxes appear to stop the original message from rendering?

2 Answers

If you have the old code from the previous lesson, your <script> tag might be placed in the <head> section. Therefore the initial JavaScript message in the <h1> tag is not allowed to display until after your script. To fix this, just set the <script> tag near the closing </body> tag. This way your <h1> is allowed to displayed before the script.js and should work as desired.

<!-- here's where you should put the script -->
    <script src="js/script.js"></script>    
  </body>
</html>
Steven Parker
Steven Parker
231,268 Points

It's normal for the program to pause until the alert box is dismissed. It's also normal for nothing to appear on the page until the program finishes.

If you see a different behavior in the video, it could be because page rendering used to be done differently in older browsers.

I also see this behaviour... I was under the impression that positioning the script tag at the bottom of the body as the last item.... would ensure that this script is run after the "Hello, Javascript! header appeared on the webpage?

Is this not the case?

Steven Parker
Steven Parker
231,268 Points

Correct placement assures that the DOM is constructed before the script runs, but in modern browsers it won't get rendered to the screen until the script finishes.