diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 16abe0a..82c544a 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 === 2) { + this.checkForCardMatch(); + } + } else if (cardInfo.state === 'flipped') { + cardInfo.state = 'default'; + this.flippedCards.pop(); + } } }