diff --git a/exercise/scripts/main.js b/exercise/scripts/main.js index b7e7fe7..2730de0 100644 --- a/exercise/scripts/main.js +++ b/exercise/scripts/main.js @@ -14,12 +14,13 @@ 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. @@ -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 we've matched all the cards, display a message.. + if (matchedCards.length >= cards.length) { alert('You matched all the cards, nice job!'); } });