-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
126 lines (95 loc) · 3.21 KB
/
main.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// Game
const cards = document.querySelectorAll('.memory-card');
let hasFlippedCard = false;
let lockBoard = false;
let firstCard, secondCard;
let randomAbc = "lehaturebashitkur";
let randomString = "";
while (randomString.length < 2) {
randomString += randomAbc[Math.floor(Math.random() * randomAbc.length)].toLocaleUpperCase();
}
let date = new Date;
let month = (date.getMonth() + 1).toString();
let day = date.getDate().toString();
let codeDate = day + month;
let scoreCount = 0;
function flipCard() {
scoreCount++;
document.getElementById("score__now").innerHTML = "urinish:" + Math.floor(scoreCount / 2);
document.getElementById("score__result").innerHTML = "Urinishlar soni:" + " " + Math.floor(scoreCount / 2) + "ta";
if (scoreCount / 2 <= 6) {
document.getElementById("prize").innerHTML = "sizga 20% skidka";
// document.getElementById("benefit").innerHTML = randomOne() + "20" + randomString + codeDate;
document.getElementById("benefit").innerHTML = '(33)803-18-99';
} else if (scoreCount / 2 > 6 && scoreCount / 2 <= 10) {
document.getElementById("prize").innerHTML = "sizga 15% skidka";
// document.getElementById("benefit").innerHTML = randomOne() + "15" + randomString + codeDate;
} else {
document.getElementById("prize").innerHTML = "sizga 15% skidka";
// document.getElementById("benefit").innerHTML = randomOne() + "15" + randomString + codeDate;
document.getElementById("benefit").innerHTML = '(33)803-18-99';
}
if (lockBoard) return;
if (this === firstCard) return;
this.classList.add('flip');
if (!hasFlippedCard) {
hasFlippedCard = true;
firstCard = this;
return;
}
hasFlippedCard = false;
secondCard = this;
checkForMatching();
}
function checkForMatching() {
let isMatch = firstCard.dataset.framework === secondCard.dataset.framework;
isMatch ? (disableCards(), endGame()) : unflipCards();
}
let count = 0;
function endGame() {
count += 1;
if (count === 6) {
showPopup();
}
}
function disableCards() {
firstCard.removeEventListener('click', flipCard);
secondCard.removeEventListener('click', flipCard);
resetBoard();
}
function unflipCards() {
lockBoard = true;
setTimeout(() => {
firstCard.classList.remove('flip');
secondCard.classList.remove('flip');
resetBoard();
}, 1300);
}
function resetBoard() {
[hasFlippedCard, lockBoard] = [false, false];
[firstCard, secondCard] = [null, null];
}
(function shuffle() {
cards.forEach(card => {
let randomPos = Math.floor(Math.random() * 12);
card.style.order = randomPos;
});
})();
cards.forEach(card => card.addEventListener('click', flipCard));
// POPUP
let popup = document.getElementById('popup');
let start = document.getElementById('start');
function hidePopup() {
popup.style.opacity = "0"
popup.style.visibility = "hidden"
}
start.addEventListener('click', hidePopup);
// Popup Endgame
let popupend = document.getElementById('popup__end');
function showPopup() {
popupend.style.opacity = "1"
popupend.style.visibility = "visible"
}
function randomOne() {
return Math.floor(Math.random() * 100000);
}