Video 11 - Updated lockBoard and resetBoard
This commit is contained in:
parent
356595ea4d
commit
b66d1b80bd
@ -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;
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user