Skip to content

Commit

Permalink
more robust fix for the multiple click problem
Browse files Browse the repository at this point in the history
turns out shift/unshift isn't queue like push and shift are queue like.

guard against any duplicate clicks
  • Loading branch information
pgwillia committed Sep 17, 2020
1 parent 6072541 commit 2db9560
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions scripts/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,12 @@ function removeCards() {
document.addEventListener('DOMContentLoaded', function() {
document.querySelectorAll('.card').forEach(function(card, index) {
card.addEventListener('click', function(event) {
if(index == chosen[chosen.length-1]){
if(chosen.includes(index)){
return;
}

chosen.unshift(index)
chosen.push(index)
clicks++

card.style.backgroundImage=`url(images/${deck[index]})`;

if(chosen.length%2==0) {
Expand Down

0 comments on commit 2db9560

Please sign in to comment.