Video 10 - Updated reserBoard
This commit is contained in:
parent
7c20778ec4
commit
356595ea4d
@ -19,15 +19,14 @@ function flipCard() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// second click
|
// second click
|
||||||
hasFlippedCard = false;
|
|
||||||
secondCard = this;
|
secondCard = this;
|
||||||
lockBoard = true;
|
|
||||||
|
|
||||||
checkForMatch();
|
checkForMatch();
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkForMatch() {
|
function checkForMatch() {
|
||||||
let isMatch = firstCard.dataset.framework === secondCard.dataset.framework;
|
let isMatch = firstCard.dataset.framework === secondCard.dataset.framework;
|
||||||
|
|
||||||
isMatch ? disableCards() : unflipCards();
|
isMatch ? disableCards() : unflipCards();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,6 +38,8 @@ function disableCards() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function unflipCards() {
|
function unflipCards() {
|
||||||
|
lockBoard = true;
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
firstCard.classList.remove('flip');
|
firstCard.classList.remove('flip');
|
||||||
secondCard.classList.remove('flip');
|
secondCard.classList.remove('flip');
|
||||||
@ -48,10 +49,8 @@ function unflipCards() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function resetBoard() {
|
function resetBoard() {
|
||||||
hasFlippedCard = false;
|
[hasFlippedCard, lockBoard] = [false, false];
|
||||||
lockBoard = false;
|
[firstCard, secondCard] = [null, null];
|
||||||
firstCard = null;
|
|
||||||
secondCard = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cards.forEach(card => card.addEventListener('click', flipCard));
|
cards.forEach(card => card.addEventListener('click', flipCard));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user