-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
87 lines (74 loc) · 1.54 KB
/
index.js
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
const cards = document.querySelectorAll(".card");
console.log(cards);
//variables
var isFlipped = false;
var firstCard;
var secondCard;
cards.forEach((card) => card.addEventListener("click", flip));
function flip() {
// console.log("Card flipped");
// console.log(this);
if(secondCard != null) {
return null;
}
this.classList.add("flip");
if (!isFlipped) {
isFlipped = true;
firstCard = this;
} else {
secondCard = this;
console.log(firstCard);
console.log(secondCard);
checkIt();
}
}
let co=0;
let fo=0;
function checkIt() {
// console.log("Checking...");
if (firstCard.dataset.image === secondCard.dataset.image ) {
success();
fo++;
if(fo==8)
{
// alert('SSS');
swal({
icon:'success',
// text: `WON !!! IN ${fo} MOVES`,
text:`WON IN ${co} MOVES 🥰 YOUR SCORE IS ${count}🤓`,
buttons: ["DONE"],
});
// swal(`SUCCESS!! in ${fo} moves`);
}
} else {
fail();
co++;
fo++;
}
}
function success() {
// console.log("Success");
firstCard.removeEventListener("click", flip);
secondCard.removeEventListener("click", flip);
reset();
}
function fail() {
// console.log("Failed");
setTimeout(() => {
firstCard.classList.remove("flip");
secondCard.classList.remove("flip");
reset();
}, 500);
}
function reset() {
isFlipped = false;
firstCard = null;
secondCard = null;
}
//TODO: shuffle
(function shuffle() {
cards.forEach((card) => {
var index = Math.floor(Math.random() * 16);
card.style.order = index;
});
})();