From dca0a9e448e4868b5d72cfc20160a6e5513efdc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CSushil?= <“sushilstar9@gmail.com”> Date: Mon, 22 Apr 2024 11:33:44 +0100 Subject: [PATCH] solved lab --- index.html | 1 + src/memory.js | 29 +++++++++++++++++++++-------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/index.html b/index.html index 9386faaf4..b4a2749f5 100644 --- a/index.html +++ b/index.html @@ -17,6 +17,7 @@

Score

Pairs guessed: 0

+ diff --git a/src/memory.js b/src/memory.js index f6644827e..7cb949070 100644 --- a/src/memory.js +++ b/src/memory.js @@ -1,18 +1,31 @@ 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; + const newCards = [...this.cards]; + this.cards.sort(() => Math.random() - 0.7); + return this.cards; + } + checkIfPair(card1, card2) { - // ... write your code here - } + this.pairsClicked++; + if (card1 === card2) { + this.pairsGuessed++; + return true; + } else { + return false; + } + } + checkIfFinished() { - // ... write your code here - } + return this.pairsGuessed === this.cards.length / 2 + } }