Skip to content
Advertisement

Javascript event listeners and arrays

I am trying to recreate a scratch-to-reveal-image effect with 3 images in an array triggered by 3 buttons. My event listener is not working, as you can see, it shows the same revealed images no matter the button. The event listener syntax has confused me a bit and I would like some help on that specifically.

The sketch image overlay is the same throughout. Can you guide me as to where I’m going wrong?

It’s a lot of code, sorry about that, but I thought it best to just put all the detail in. Thank you in advance!

JavaScript
JavaScript
JavaScript

Advertisement

Answer

Look at the change I have made in the EventListener.

The changes I made are: Added class on the buttons so that they can be selected together. When placing the listener for the loop also puts “date” information on the buttons. This information is a serial number that corresponds to the Array record

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement