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

Score

- + + + diff --git a/src/memory.js b/src/memory.js index f6644827e..0e979005e 100644 --- a/src/memory.js +++ b/src/memory.js @@ -1,18 +1,38 @@ class MemoryGame { constructor(cards) { this.cards = cards; - // add the rest of the class properties here - } + + this.pickedCards = []; + this.pairsClicked = 0; + this.pairsGuessed = 0; + } shuffleCards() { - // ... write your code here + if (!this.cards) return undefined; + + for (let i = this.cards.length -1; i > 0; i--) { + let 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 + + return this.pairsClicked++; + if (card1 === card2){ + this.pairsGuessed++; + + } else { + return false; + } + + } checkIfFinished() { - // ... write your code here + return this.pairsGuessed === this.cards.length / 2; } }