-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
71 lines (66 loc) · 2.07 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
let check = document.querySelector(".check");
let input = document.querySelector(".input");
let text = document.querySelector(".text");
let first = document.querySelector(".first");
let second = document.querySelector(".second");
let text2 = document.querySelector(".text2");
let testNumber = document.querySelector(".test-number");
let again = document.querySelector(".again");
let score = document.querySelector(".score");
let scoreNumber = document.querySelector(".score-number");
let random = Math.floor(Math.random() * 101);
console.log(random);
check.addEventListener("click", () => {
const guess = parseInt(input.value, 10);
click.play();
if (isNaN(guess) || guess < 1 || guess > 100) {
text.textContent = "Enter a number between 1 and 100!";
} else {
if (guess === random) {
text.textContent = "Congratulations, You Guess It Right! 👏";
win.play();
// lose.pause();
tekrar();
} else if (guess < random) {
text.textContent = " 👆Increase the number👆";
first.textContent = guess;
text2.style.display = "block";
testNumber.textContent++;
} else {
text.textContent = "👇Reduce the number👇";
second.textContent = guess;
text2.style.display = "block";
testNumber.textContent++;
}
if (scoreNumber.textContent > 1) {
scoreNumber.textContent--;
} else if (scoreNumber.textContent == 1) {
text.textContent = "😞GAME OVER😞";
tekrar();
lose.play();
}
}
});
document.addEventListener("keydown", function (e) {
if (e.key === "Enter") {
check.click();
}
});
window.addEventListener("load", () => {
input.focus();
});
again.addEventListener("click", function () {
random = Math.floor(Math.random() * 101);
console.log(random);
window.location.reload();
click.play();
});
let tekrar = () => {
document.querySelector("h1").textContent = "";
document.querySelector("h2").textContent = "";
input.style.display = "none";
check.style.display = "none";
score.style.display = "none";
again.style.display = "block";
text2.style.display = "none";
};