Video 9 - Updated lockBoard

This commit is contained in:
Marina Ferreira 2018-07-29 10:10:21 -03:00
parent bf74d11250
commit 7c20778ec4
2 changed files with 5 additions and 3 deletions

View File

@ -23,6 +23,7 @@ function flipCard() {
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();
} }

View File

@ -6,6 +6,7 @@ let firstCard, secondCard;
function flipCard() { function flipCard() {
if (lockBoard) return; if (lockBoard) return;
this.classList.add('flip'); this.classList.add('flip');
if (!hasFlippedCard) { if (!hasFlippedCard) {
@ -19,24 +20,24 @@ function flipCard() {
// second click // second click
hasFlippedCard = false; 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();
} }
function disableCards() { function disableCards() {
firstCard.removeEventListener('click', flipCard); firstCard.removeEventListener('click', flipCard);
secondCard.removeEventListener('click', flipCard); secondCard.removeEventListener('click', flipCard);
lockBoard = false;
} }
function unflipCards() { function unflipCards() {
lockBoard = true;
setTimeout(() => { setTimeout(() => {
firstCard.classList.remove('flip'); firstCard.classList.remove('flip');
secondCard.classList.remove('flip'); secondCard.classList.remove('flip');