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 Loops, Arrays and Objects Tracking Multiple Items with Arrays Build a Quiz Challenge, Part 1 Solution

What triggers the js?

I couldn't figure out, how to run that code in my HTML page. there isn't any trigger to do so, so how come when page run the code on load?

3 Answers

Steven Parker
Steven Parker
231,248 Points

Normally, the JavaScript code is loaded by a <script> tag in the HTML, and it runs immediately after it is loaded.

No I mean, in the video how does Dave make the script load when the page loads. Either a event happens or something get called?

Steven Parker
Steven Parker
231,248 Points

I think we are talking about the same thing. When the page loads, the HTML contains one or more <script> tags that identify the JavaScript modules. As each tag is encountered during loading, the script code is loaded and immediately executed. This is an automatic browser function and does not require anything special in the code.