From 6dad2b4558f6e095cf5939cb8a1f4bb01e22659a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alberto=20Codo=C3=B1er=20Gea?= Date: Thu, 10 Oct 2024 22:58:33 +0200 Subject: [PATCH] Iteration 3 is missing --- index.html | 6 ++++-- src/memory.js | 30 +++++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 7 deletions(-) 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; } }