-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
47 lines (40 loc) · 1.26 KB
/
script.js
File metadata and controls
47 lines (40 loc) · 1.26 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
const correctBoxes = document.querySelectorAll(".box--correct");
const boxes = document.querySelectorAll(".box");
const winScreen = document.querySelector(".win-screen");
const loseScreen = document.querySelector(".lose-screen");
let incorrectGuesses = 0;
let guessCooldown = false;
correctBoxes.forEach(function (correctBox) {
correctBox.addEventListener("mouseover", function () {
if (!guessCooldown) {
correctBox.classList.add("box--locked");
const lockedBoxes = document.querySelectorAll(".box--correct.box--locked");
if (lockedBoxes.length === correctBoxes.length) {
showWinScreen();
}
}
});
});
boxes.forEach(function (box) {
if (!box.classList.contains("box--correct")) {
box.addEventListener("mouseover", function () {
if (!guessCooldown && !box.classList.contains("box--locked")) {
box.classList.add("box--locked");
incorrectGuesses++;
if (incorrectGuesses === 3) {
showLoseScreen();
}
guessCooldown = true;
setTimeout(function() {
guessCooldown = false;
}, 1000);
}
});
}
});
function showWinScreen() {
winScreen.classList.add("win-screen--show");
}
function showLoseScreen() {
loseScreen.classList.add("lose-screen--show");
}