JavaScript Events Worksheet
Questions
Question 1
What is an 'event handler'?
An event handler is a function or a block of code that is executed in response to a specific event occurring, such as a user interaction (like a click or keypress) or a system-generated event (like page load).
Question 2
How are event handlers invoked?
Event handlers are invoked automatically by the browser when the specified event occurs on the element they are attached to.
Question 3
What is an 'anonymous' function?
An anonymous function is a function that is defined without a name. It is often used as an argument to other functions, such as event handlers, where the function is used only once and does not need to be referenced elsewhere.
Question 4
Explain what the addEventListener() method of a DOM element is, and explain the purpose of each of it's parameters.
The addEventListener() method of a DOM element is used to attach an event handler to the element. It takes two main parameters: the first parameter is a string representing the event type (e.g., "click", "mouseover"), and the second parameter is the function that will be executed when the event occurs.
Coding Problems
Coding Problems - See the 'script' tag below this h3 tag. You will have to write some JavaScript code in it.
Always test your work! Check the console log to make sure there are no errors.
Orange
Green