-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathscript.js
More file actions
46 lines (40 loc) · 1.42 KB
/
script.js
File metadata and controls
46 lines (40 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const cards = document.querySelectorAll(".card");
const flippedCards = [];
function flipCard() {
if (flippedCards.length >= 2) {
return;
}
this.classList.toggle("is-flipped");
flippedCards.push(this);
if (flippedCards.length === 2) {
const [card1, card2] = flippedCards;
setTimeout(() => {
if (flippedCards[0].classList[2] === flippedCards[1].classList[2]) {
flippedCards.forEach((card) => card.classList.remove("is-flipped"));
flippedCards.length = 0;
} else {
if (card1.classList[1] === card2.classList[1]) {
flippedCards.forEach((card) => (card.style.display = "none"));
} else {
flippedCards.forEach((card) => card.classList.remove("is-flipped"));
}
flippedCards.length = 0;
}
const remainingCards = document.querySelectorAll(
'.card:not([style="display: none;"])'
);
if (remainingCards.length === 6) {
document.body.style.background =
"linear-gradient(180deg, rgb(205, 194, 172) 0%, rgba(0, 106, 171, 1) 77%)";
}
if (remainingCards.length === 2) {
document.body.style.background =
"linear-gradient(180deg, rgba(124,185,242,1) 0%, rgba(0,106,171,1) 77%)";
}
if (!remainingCards.length) {
document.querySelector("#congrats").style.display = "flex";
}
}, 1000);
}
}
cards.forEach((card) => card.addEventListener("click", flipCard));