Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions exercise/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,31 @@ 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');
}

// 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!');
}
});
Expand Down