diff --git a/index.html b/index.html index 9386faaf4..394e86009 100644 --- a/index.html +++ b/index.html @@ -6,6 +6,7 @@ Superhero Memory Game +
@@ -17,7 +18,9 @@

Score

Pairs guessed: 0

- + + + diff --git a/src/memory.js b/src/memory.js index f6644827e..00460955b 100644 --- a/src/memory.js +++ b/src/memory.js @@ -1,18 +1,39 @@ 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; } + let oldElement; + for (let i = this.cards.length - 1; i > 0; i--) { + let rand = Math.floor(Math.random() * (i + 1)); + oldElement = this.cards[i]; + this.cards[i] = this.cards[rand]; + this.cards[rand] = oldElement; + } + return this.cards; +}; + checkIfPair(card1, card2) { - // ... write your code here + this.pairsClicked++; + if (card1 === card2){ + this.pairsGuessed++; + return true; + } + return false; } checkIfFinished() { - // ... write your code here + if (this.pairsGuessed === this.cards.length/2){ + return true; + } + return false; } }