-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
42 lines (38 loc) · 1.8 KB
/
index.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
let secretNumber = Math.trunc(Math.random() * 20) + 1;
let highScore = 0;
let score = 20;
document.querySelector('.check').addEventListener('click', function () {
const guess = Number(document.querySelector('.guess').value);
if (!guess) {
document.querySelector('.message').textContent = 'No Number...';
} else if (guess === secretNumber) {
document.querySelector('.message').textContent = "Correct Number...";
score = score + 5;
document.querySelector('.score').textContent = score;
document.querySelector('.number').textContent = secretNumber;
document.querySelector('body').style.backgroundColor = "Green";
document.querySelector('.number').style.width = '30rem';
if (score > highScore) {
highScore = score;
document.querySelector('.highscore').textContent = highScore;
}
} else if (guess !== secretNumber) {
if (score > 1) {
document.querySelector('.message').textContent = guess > secretNumber ? "Guess is High..." : "Guess is Low...";
score = score - 1;
document.querySelector('.score').textContent = score;
} else {
document.querySelector('.message').textContent = "GAME OVER";
document.querySelector('.score').textContent = 0;
}
}
});
document.querySelector('.again').addEventListener('click', function () {
secretNumber = Math.trunc(Math.random() * 20) + 1;
document.querySelector('.score').textContent = 20;
document.querySelector('.message').textContent = 'Start guessing...';
document.querySelector('.guess').value = '';
document.querySelector('body').style.background = 'rgb(0, 4, 40)';
document.querySelector('.number').style.width = '15rem';
document.querySelector('.number').textContent = '?';
})