Wack-A-Mole game

Hi guys,
I’m trying to create a wack-A-Mole game but im having issues.
First off, my z index property is not working as the “moles” are supposed to be behind the “dirt”.
Also, i cant even properly select the moles, i keep getting the error “is not a function” even though the syntax looks fine.
I would really appreciate some help. Thank you.

https://codepen.io/Modestas/pen/LjOqjM

You need both dirt and moles be in the same container to be able to use z-index.

Also getElementsByClassNames returns array-like data structure. Use querySelectorAll instead.

Here’s a fixed version:

1 Like