Simon Game - User Input multiple clicks effect - 2

Simon Game - User Input multiple clicks effect - 2
0

#1

Ok, so this is a follow-up topic. My game on the User Clicks stage generates the effect of multiple color-clicks. I would really like to understand why, because I have removed all loops from my solution, so it must be the Timeout, but I seem to have cleared that as well. The codepen is here: https://codepen.io/Leighenne/pen/XzjVdO?editors=1111
Thanks in advance!


#2

You seem to be running the code that adds an event listener to .piece multiple times.


#3

I tried to help it with add/remove clickable class “color”. If it works as intended, it is supposed to add/remove class after/before each user click as here: https://codepen.io/Leighenne/pen/MOjQpY?editors=1111 But I keep getting the same effect :tired_face:


#4

Ok, I solved me problem. For anyone that will come across the same issue. here is the solution: if on each new round, you were starting the user input with a type of function, where you assign click event to your color buttons, make sure not to add this event again before the new round starts, because then you will assign it twice and on with each new round, clicking on the color will run the assigned function x-number-of-round times. I handled this with off-click. maybe this link will be helpful: https://stackoverflow.com/questions/34225115/removing-a-class-doesnt-disable-the-event-listener-function-associated-with-the
Happy coding and good luck with your Simon game!