Video 10 - Updated reserBoard

This commit is contained in:
Marina Ferreira 2018-07-29 10:16:30 -03:00
parent 7c20778ec4
commit 356595ea4d

View File

@ -19,15 +19,14 @@ function flipCard() {
}
// second click
hasFlippedCard = false;
secondCard = this;
lockBoard = true;
checkForMatch();
}
function checkForMatch() {
let isMatch = firstCard.dataset.framework === secondCard.dataset.framework;
isMatch ? disableCards() : unflipCards();
}
@ -39,6 +38,8 @@ function disableCards() {
}
function unflipCards() {
lockBoard = true;
setTimeout(() => {
firstCard.classList.remove('flip');
secondCard.classList.remove('flip');
@ -48,10 +49,8 @@ function unflipCards() {
}
function resetBoard() {
hasFlippedCard = false;
lockBoard = false;
firstCard = null;
secondCard = null;
[hasFlippedCard, lockBoard] = [false, false];
[firstCard, secondCard] = [null, null];
}
cards.forEach(card => card.addEventListener('click', flipCard));