Video 11 - Updated lockBoard and resetBoard

This commit is contained in:
Marina Ferreira 2018-07-29 10:25:36 -03:00
parent 356595ea4d
commit b66d1b80bd

View File

@ -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,16 +49,14 @@ function unflipCards() {
} }
function resetBoard() { function resetBoard() {
hasFlippedCard = false; [hasFlippedCard, lockBoard] = [false, false];
lockBoard = false; [firstCard, secondCard] = [null, null];
firstCard = null;
secondCard = null;
} }
(function shuffle() { (function shuffle() {
cards.forEach(card => { cards.forEach(card => {
let ramdomPos = Math.floor(Math.random() * 12); let randomPos = Math.floor(Math.random() * 12);
card.style.order = ramdomPos; card.style.order = randomPos;
}); });
})(); })();