Exercises
The following questions are not mandatory.
-
What is an Event?
- Create a simple HTML page with a button. Write a JavaScript function that listens for the button's click event and logs a message to the console when the button is clicked.
- Add an event listener to an input field that logs the input value whenever it changes.
- Create a script that listens for the
DOMContentLoaded
event and logs a message when the page has finished loading.
-
Types of Events
- Write a script that listens for
mouseover
andmouseout
events on a specific element and changes its background color accordingly. - Create a simple form with a submit button. Add a submit event listener to the form that prevents the default form submission and logs the form data to the console.
- Write a script that listens for
-
Accessing the event information
- Write a script that listens for the
mousemove
event and logs the current mouse coordinates (clientX and clientY) to the console. - Implement a function that listens for the
keydown
event and logs the key code and whether the Shift, Ctrl, or Alt key was pressed (use theevent.shiftKey
,event.ctrlKey
, andevent.altKey
properties).
- Write a script that listens for the