Video 9 - Updated lockBoard
This commit is contained in:
parent
bf74d11250
commit
7c20778ec4
@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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');
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user