-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
49 lines (45 loc) · 1.1 KB
/
App.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
const crow = document.querySelectorAll(".crow");
let div = document.createElement("div");
div.style.fontSize = "calc(10px + 5vw)";
const wrapper = document.querySelector(".wrapper");
wrapper.appendChild(div);
let count = 0;
const timer = document.querySelector(".timer");
let time = 15;
setInterval(timeOver, 1000);
function timeOver() {
if (time > 0) {
time--;
timer.innerText = `${time}s`;
}
if (count === 6) {
timer.innerText = "0s";
}
}
crow.forEach((el) => {
el.addEventListener("click", (e) => {
e.target.style.display = "none";
count++;
document.querySelector(".score").innerHTML = `<p>Score</p>
<p>${count}</p>
`;
over(); // Check if game is over after each click
});
});
function over() {
if (count === 6) {
div.innerText = "win";
wrapper.style.animation = "none";
timeOver();
}
}
// Timeout function to end the game after 5 seconds
setTimeout(() => {
if (count <= 5) {
div.innerText = "Game Over";
wrapper.style.animation = "none";
}
crow.forEach((el) => {
el.style.display = "none"; // Hide all crow elements
});
}, 15000);