javascript - Problems with function, firing click() multiple times -


i have problem project i'm doing; https://codepen.io/argestis/pen/glrabq?editors=0001

i have function, simon says game. far want push values of colors array , compare array function. working until empty value array i'm using push values user should enter giu, when go function gameon() , try start pushing values click triggers multiple times.

here's reference function, on console of codepen shared above guys can see error i'm getting.

function gameon() {     game.blue.on("click", function() {          game.guesswhat.push(1);         console.log("i @ blue")         if (game.guesswhat.length !== game.count.length) {          } else {             verifysequence();         }      });      game.red.on("click", function() {         console.log("i @ red")         game.guesswhat.push(2);         if (game.guesswhat.length !== game.count.length) {          } else {             verifysequence();         }     });      game.green.on("click", function() {         console.log("i @ green")         game.guesswhat.push(3);         if (game.guesswhat.length !== game.count.length) {          } else {             verifysequence();         }     });      game.yellow.on("click", function() {         console.log("i @ yellow")         game.guesswhat.push(4);         if (game.guesswhat.length !== game.count.length) {          } else {             verifysequence();         }       }); } 

thank time, guys!

you register multiple 'click' event on same item when calling verifysequence(). can unregister click event prior register solve that

//problem in verifysequence()  function verifysequence() {  ...    if (verify) {      console.log("this game.guesswhat: " + game.guesswhat);      //when call nextround() register click event on same item (multiple times)      nextround();    } else {      clearuser();    }  }  }      //making sure unregister 'click' event before add 1  game.blue.off("click").on("click", function() {    ...  });    game.red.off("click").on("click", function() {    ...  });    game.green.off("click").on("click", function() {    ...  });    game.yellow.off("click").on("click", function() {    ...  });


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -