P3.9: Event Listeners & Actions

Events are actions that happen on the page (clicks, keyboard inputs, page scrolls).


1. Listening to Events

const btn = document.querySelector("button");
btn.addEventListener("click", () => {
  alert("Button clicked!");
});

🎓 Practice Assignment Tasks

  • Create a button and a counter text element.
  • Increment the count every time the button is clicked.
Stuck? Hints available
// Write your JavaScript logic here
// Click 'Run Code' to see console outputs below
🔒 Code requirements not met yet. Complete the tasks above.
🔒 Complete the Practice Assignment above to unlock completion.
Advertisement
NS
Ask Nextsem
AI Mode
NS
Home
Course
Playground