Cannot select class using JavaScript

Hi guys.
I’m trying to select the “mole” class in my “wack-a-mole” application using JavaScript, but its not working for some reason.

Here is my code:
https://codepen.io/Modestas/pen/LjOqjM/

querySelectorAll() returns an array-like object. addEventListener only works on a single DOM element. So, you will need to loop over the querySelectorAll() result and call addEventListener for all of them.

1 Like

why doesn’t this work?

mole.forEach = e => {
  e.addEventListener("click", ()=> {
    alert("Hi");
  })
}