diff --git a/index.html b/index.html index 9386faaf4..893d72cee 100644 --- a/index.html +++ b/index.html @@ -5,7 +5,8 @@ Superhero Memory Game - + +
@@ -17,7 +18,7 @@

Score

Pairs guessed: 0

- - + + diff --git a/src/memory.js b/src/memory.js index f6644827e..830cdf51d 100644 --- a/src/memory.js +++ b/src/memory.js @@ -1,18 +1,32 @@ class MemoryGame { constructor(cards) { this.cards = cards; - // add the rest of the class properties here + this.pickedCards = []; + this.pairsClicked = 0; + this.pairsGuessed = 0; + this.shuffleCards(); } shuffleCards() { - // ... write your code here + if (!this.cards) return undefined; + + for (let i = this.cards.length - 1; i > 0; i--) { + const j = Math.floor(Math.random() * (i + 1)); + [this.cards[i], this.cards[j]] = [this.cards[j], this.cards[i]]; + } } checkIfPair(card1, card2) { - // ... write your code here + this.pairsClicked++; + if (card1 === card2) { + this.pairsGuessed++; + return true; + } else { + return false; + } } checkIfFinished() { - // ... write your code here + return this.pairsGuessed === this.cards.length / 2; } -} +} \ No newline at end of file