-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscr.js
More file actions
149 lines (134 loc) · 4.18 KB
/
scr.js
File metadata and controls
149 lines (134 loc) · 4.18 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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
const td = document.querySelectorAll(".td");
const timer = document.querySelector(".timer")
const wrong = document.querySelector(".wrong")
const btn = document.querySelector(".btn");
const level = document.querySelectorAll(".level");
const d_container = document.querySelector(".d-container");
const alert = document.querySelector(".alert");
const fade = document.querySelector(".fade");
const alert_text = document.querySelector(".alert-text");
const progress = document.querySelector(".progress");
let tempLevel=6;
let checkLevel=6;
let timeLevel = 6000;
level.forEach( lvl => {
lvl.addEventListener("click", e =>{
if(e.target.classList.contains("easy")){
e.target.classList.add("selected");
level[1].classList.remove("selected");
level[2].classList.remove("selected");
tempLevel = 6
checkLevel = 6
timeLevel = 6000
}
else if(e.target.classList.contains("medium")){
e.target.classList.add("selected");
level[0].classList.remove("selected");
level[2].classList.remove("selected");
tempLevel = 4
checkLevel = 4
timeLevel = 4000
}
else if(e.target.classList.contains("hard")){
e.target.classList.add("selected");
level[0].classList.remove("selected");
level[1].classList.remove("selected");
tempLevel = 2
checkLevel = 2
timeLevel = 2000
}
})
})
let temp=[];
btn.addEventListener("click", b =>{
btn.disabled = true;
level.forEach(lvl => {
lvl.disabled = true
if(tempLevel==6){
level[0].classList.add("selected")
}
});
for(let i=0; i<6; i++)
td[Math.floor(Math.random() * td.length)].style.backgroundColor = "rgb(255, 33, 113)"
td.forEach( td => {
if(td.style.backgroundColor === "rgb(255, 33, 113)"){
temp.push(td)
}})
let c = checkLevel
let op =1
const u = setInterval(()=> {
if(c==0) {
timer.style.opacity = 0
clearInterval(u)
}
timer.innerHTML = c
c--
},900)
setInterval(()=>{
td.forEach((e) => {
if(e.style.backgroundColor==="rgb(255, 33, 113)"){
e.style.backgroundColor="rgb(255, 250, 215)"
}
e.classList.add("hover")
e.addEventListener("click",a => {
check(a.target,temp,tempLevel)
})
});
},timeLevel)
wrong.innerHTML = `${tempLevel} chances`
})
function check(e,temp,tempLevel) {
let c =0
if(temp.includes(e)) {
e.style.backgroundColor = "rgb(31, 163, 83)"
e.style.border = "none"
}
if(!(temp.includes(e))) {
e.style.border = "none"
e.style.backgroundColor = "rgb(255, 144, 187)"
}
td.forEach( td => {
td.classList.remove("hover")
if(td.style.backgroundColor === "rgb(31, 163, 83)") c++
if(td.style.backgroundColor === "rgb(255, 144, 187)") tempLevel--
})
wrong.innerHTML = `${tempLevel} chances`
let i=0
let width = 0
if(c>=temp.length) {
progressBar()
alert.style.display = "block"
fade.style.display = "block"
alert_text.style.color="rgb(31, 163, 83)"
alert_text.textContent = "You Win!"
setInterval( ()=> location.reload(),3250)
}
if(tempLevel==0){
progressBar()
alert.style.display = "inline"
fade.style.display = "block"
alert_text.style.color="rgb(255, 144, 187)"
alert_text.textContent = "You Lose!"
setInterval( ()=> location.reload(),3250)
}
}
function restart(){
location.reload()
}
function progressBar(){
let i = 0
let width = 0
if (i == 0) {
i = 1;
let id = setInterval(clearInter, 20);
function clearInter() {
if (width >= 100) {
clearInterval(id);
i = 0;
} else {
width++;
progress.style.width = width + "%";
}
}
}
}