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