-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
86 lines (66 loc) · 2.45 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
'use strict';
let SecretNum = Math.trunc(Math.random() * 20) + 1;
let score = 20;
let highscore = 0;
const displayMessage = function (message) {
document.querySelector('.message').textContent = message;
}
const numBer = document.querySelector('.number');
const scoRe = document.querySelector('.score');
document.querySelector('.check').addEventListener('click', function () {
const guess = Number(document.querySelector('.guess').value);
console.log(guess);
if (!guess) {
displayMessage('⚠ No Number......');
} else if (guess === SecretNum) {
displayMessage('Correct Number');
document.querySelector('body').style.backgroundColor = '#60b347';
numBer.style.width = '30rem';
numBer.textContent = SecretNum;
if (score > highscore) {
highscore = score;
document.querySelector('.highscore').textContent = highscore;
}
}
else {
if (score > 1) {
displayMessage(guess > SecretNum ? 'Too High' : 'Too low');
score--;
scoRe.textContent = score;
} else {
displayMessage('You Lost The game !!!!');
scoRe.textContent = 0;
}
}
// else if (guess > SecretNum) {
// if (score > 1) {
// document.querySelector('.message').textContent = 'Too High';
// score--;
// document.querySelector('.score').textContent = score;
// } else {
// document.querySelector('.message').textContent = 'You Lost The game !!!!';
// document.querySelector('.score').textContent = 0;
// }
// }
// else if (guess < SecretNum) {
// if (score > 1) {
// document.querySelector('.message').textContent = 'Too Low';
// score--;
// document.querySelector('.score').textContent = score;
// }
// else {
// document.querySelector('.message').textContent = '🔥You Lost The game !!!!';
// document.querySelector('.score').textContent = 0;
// }
// }
});
document.querySelector('.again').addEventListener('click', function () {
SecretNum = Math.trunc(Math.random() * 20) + 1;
score = 20;
scoRe.textContent = 20;
document.querySelector('body').style.backgroundColor = '#222';
numBer.textContent = '?';
document.querySelector('.guess').value = '';
numBer.style.width = '15rem';
displayMessage('Start guessing...');
});