diff --git a/index.html b/index.html index 9386faaf4..5bb4a8f63 100644 --- a/index.html +++ b/index.html @@ -5,12 +5,13 @@ Superhero Memory Game - +

Superhero Memory Game

+

Score

Pairs clicked: 0

@@ -18,6 +19,7 @@

Score

- + + diff --git a/src/memory.js b/src/memory.js index f6644827e..a0ca48c8e 100644 --- a/src/memory.js +++ b/src/memory.js @@ -1,18 +1,34 @@ 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 || !Array.isArray(this.cards)) { + return undefined; + } + this.cards.sort(() => Math.random() - 0.5); + 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 + return this.pairsGuessed === (this.cards.length / 2); } }