Exercises

The following questions are not mandatory.

  1. 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.
  2. Types of Events

    • Write a script that listens for mouseover and mouseout 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.
  3. 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 the event.shiftKey, event.ctrlKey, and event.altKey properties).