Can't switch between two states

I’m currently making a javaScript color flipper based on the 15 free javascript project, but with my own code. I’m currently trying to find how I’m able to switch between two states of the game, simple and complex.

When i change state to simple, and press the call to action button, the color still changes. Can anyone help?


So, based on state, you addEventListener the appropriate function, right? But do you ever actually remove them (using removeEventListener)?

If you add a new listener, the old one is not removed. Listeners can stack, letting you add more as needed - but if you don’t want one, you must explicitly remove it.

1 Like

Hi, i solved the solution, ironically, moments after i post this message, but you’re right I never knew removeEventListener exist and i should have done that.

I just restructure my code and it’s all good thanks man

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.