diff --git a/exercise/scripts/main.js b/exercise/scripts/main.js index b7e7fe7..06b503a 100644 --- a/exercise/scripts/main.js +++ b/exercise/scripts/main.js @@ -14,17 +14,18 @@ window.addEventListener('DOMContentLoaded', function() { // collection of selected cards and apply the correct CSS class. if (selectedCards.length < 2) { card.classList.add('is-selected'); + selectedCards.push(card); } // If we have selected two cards, see if they match. if (selectedCards.length === 2) { var card1 = selectedCards[0]; - var card2 = selectedCards[0]; + var card2 = selectedCards[1]; // If the cards match, add them to the collection of matched cards and // apply the correct CSS class. if (card1.innerText === card2.innerText) { - matchedCards.push(card1, card2); + matchedCards.push(card1, card2); card1.classList.add('is-matched'); card2.classList.add('is-matched'); } @@ -32,12 +33,12 @@ window.addEventListener('DOMContentLoaded', function() { // Regardless of whether or not the cards match, deselect them and reset // the collection of matched cards. card1.classList.remove('is-selected'); - card3.classList.remove('is-selected'); + card2.classList.remove('is-selected'); selectedCards = []; } // If we've matched all the cards, display a message. - if (matchedCards.length > cards.length) { + if (matchedCards.length >= cards.length) { alert('You matched all the cards, nice job!'); } });