From e8aa46315bdde5922551da2fbdad36f173cf2600 Mon Sep 17 00:00:00 2001 From: bruna Date: Sat, 8 Nov 2025 20:58:18 +0100 Subject: [PATCH] lab memory --- index.html | 6 ++++-- src/memory.js | 22 +++++++++++++++++++--- 2 files changed, 23 insertions(+), 5 deletions(-) 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); } }