Video 9 - Updated lockBoard
This commit is contained in:
parent
bf74d11250
commit
7c20778ec4
@ -23,6 +23,7 @@ function flipCard() {
|
||||
|
||||
function checkForMatch() {
|
||||
let isMatch = firstCard.dataset.framework === secondCard.dataset.framework;
|
||||
|
||||
isMatch ? disableCards() : unflipCards();
|
||||
}
|
||||
|
||||
|
||||
@ -6,6 +6,7 @@ let firstCard, secondCard;
|
||||
|
||||
function flipCard() {
|
||||
if (lockBoard) return;
|
||||
|
||||
this.classList.add('flip');
|
||||
|
||||
if (!hasFlippedCard) {
|
||||
@ -19,24 +20,24 @@ function flipCard() {
|
||||
// second click
|
||||
hasFlippedCard = false;
|
||||
secondCard = this;
|
||||
lockBoard = true;
|
||||
|
||||
checkForMatch();
|
||||
}
|
||||
|
||||
function checkForMatch() {
|
||||
let isMatch = firstCard.dataset.framework === secondCard.dataset.framework;
|
||||
|
||||
isMatch ? disableCards() : unflipCards();
|
||||
}
|
||||
|
||||
function disableCards() {
|
||||
firstCard.removeEventListener('click', flipCard);
|
||||
secondCard.removeEventListener('click', flipCard);
|
||||
|
||||
lockBoard = false;
|
||||
}
|
||||
|
||||
function unflipCards() {
|
||||
lockBoard = true;
|
||||
|
||||
setTimeout(() => {
|
||||
firstCard.classList.remove('flip');
|
||||
secondCard.classList.remove('flip');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user