From e9cd2bf4d4c97efbc00640646047706b0bca0d74 Mon Sep 17 00:00:00 2001 From: Elisei Nicolae Date: Tue, 2 Nov 2021 20:10:09 +0200 Subject: [PATCH 1/2] fixed bug #2 --- src/app/app.component.ts | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 16abe0a..b22cc22 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -57,18 +57,19 @@ export class AppComponent implements OnInit { cardClicked(index: number): void { const cardInfo = this.cards[index]; - if (cardInfo.state === 'default' && this.flippedCards.length < 2) { - cardInfo.state = 'flipped'; - this.flippedCards.push(cardInfo); + if (this.flippedCards.length < 2) { + if (cardInfo.state === 'default') { + cardInfo.state = 'flipped'; + this.flippedCards.push(cardInfo); - if (this.flippedCards.length > 1) { - this.checkForCardMatch(); - } - - } else if (cardInfo.state === 'flipped') { - cardInfo.state = 'default'; - this.flippedCards.pop(); + if (this.flippedCards.length > 1) { + this.checkForCardMatch(); + } + } else if (cardInfo.state === 'flipped') { + cardInfo.state = 'default'; + this.flippedCards.pop(); + } } } From b80b56ea9551c3047472ec81069e21bf1b4d04eb Mon Sep 17 00:00:00 2001 From: Elisei Nicolae Date: Tue, 2 Nov 2021 20:11:50 +0200 Subject: [PATCH 2/2] minor refactor. --- src/app/app.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index b22cc22..82c544a 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -62,7 +62,7 @@ export class AppComponent implements OnInit { cardInfo.state = 'flipped'; this.flippedCards.push(cardInfo); - if (this.flippedCards.length > 1) { + if (this.flippedCards.length === 2) { this.checkForCardMatch(); }