-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
62 lines (59 loc) · 2.83 KB
/
script.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
"use strict";
// let a;
let guessNumber = Math.trunc(Math.random() * 20) + 1;
console.log(guessNumber);
document.querySelector(".check").addEventListener("click", function () {
const guess = Number(document.querySelector(".guess").value);
if (!guess) {
document.querySelector(".message").textContent = "No number!";
} else if (guess > guessNumber) {
if (Number(document.querySelector(".score").textContent) > 1) {
document.querySelector(".message").textContent = "High";
const x = Number(document.querySelector(".score").textContent);
document.querySelector(".score").textContent = x - 1;
document.querySelector("body").style.backgroundColor = "#222";
} else {
document.querySelector(".message").textContent = "You Lost The Game!";
document.querySelector("body").style.backgroundColor = "#ec1616";
document.querySelector(".score").textContent = 0;
}
} else if (guess < guessNumber) {
if (Number(document.querySelector(".score").textContent) > 1) {
document.querySelector(".message").textContent = "Low";
const x = Number(document.querySelector(".score").textContent);
document.querySelector(".score").textContent = x - 1;
document.querySelector("body").style.backgroundColor = "#222";
} else {
document.querySelector(".message").textContent = "You Lost The Game!";
document.querySelector("body").style.backgroundColor = "#ec1616";
document.querySelector(".score").textContent = 0;
}
} else {
if (Number(document.querySelector(".score").textContent) === 0) {
document.querySelector(".message").textContent = "You Lost The Game!";
document.querySelector("body").style.backgroundColor = "#ec1616";
} else {
document.querySelector(".number").textContent = guessNumber;
document.querySelector(".message").textContent = "Correct Guess";
document.querySelector("body").style.backgroundColor = "#83e734";
document.querySelector(".number").style.width = "30rem";
if (
Number(document.querySelector(".highscore").textContent) <
Number(document.querySelector(".score").textContent)
) {
document.querySelector(".highscore").textContent =
document.querySelector(".score").textContent;
}
}
}
});
document.querySelector(".again").addEventListener("click", function () {
// a = Number(document.querySelector(".highscore").textContent);
guessNumber = Math.trunc(Math.random() * 20) + 1;
console.log(guessNumber);
document.querySelector(".number").style.width = "15rem";
document.querySelector("body").style.backgroundColor = "#222";
document.querySelector(".message").textContent = "Start Guessing...";
document.querySelector(".number").textContent = "?";
document.querySelector(".score").textContent = 20;
});