addEventListener vs onclick: auto executing problem RESOLVED

I’ve just finished the Random Quote Generator project, but am trying to switch from onclick (which seems to work great) to addEventListener, and I’m not sure why it’s not working. They auto fire, without me clicking.

Caution: contains spoilers
I’m not sure how to paste my code in here, but the link to codepen is

Any help with solving the addEvent problem in changing images on click would be much appreciated.

Cheers,

Rich

If you want to pass parameters to a listener function inside, addEventListener() you should be using an anonymous function or with an arrow function (ES6). Take a look at the Event listener with anonymous function and Event listener with an arrow function sections of the documentation for addEventListener().

I hope that helps!

1 Like

Thank you! That was it!