Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
212,135 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
212,135 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.