79765265

Date: 2025-09-15 14:22:57
Score: 0.5
Natty:
Report link

What you should be doing is the following:

let buttons = document.querySelectorAll("button");

buttons.forEach(myFunction);

function myFunction(button){
    button.addEventListener("click", function() {
        alert("I got clicked!");
    });
};

This way you are attaching the event to each button, as opposed to add 7 events to window ( that is the global object ). The forEach method of an array calls the supplied function with each element as argument: ForEach

Reasons:
  • Has code block (-0.5):
  • Starts with a question (0.5): What you
  • Low reputation (0.5):
Posted by: JoaoFCarvalho