-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
69 lines (52 loc) · 1.59 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
'use strict';
let secretNum;
const inputValue = document.querySelector('.guess');
const btnCheck = document.querySelector('.check');
const btnAgain = document.querySelector('.again');
const labelSecretNum = document.querySelector('.label-secretnumber');
const labelMsg = document.querySelector('.label-message');
const labelScore = document.querySelector('.score');
let setScore = Number(labelScore.textContent);
const originalScore = setScore;
function display()
{
labelSecretNum.textContent ="?";
inputValue.textContent = " ";
btnCheck.style.display = "initial";
labelMsg.textContent = "Start guessing...";
secretNum = Math.floor((Math.random()*20) +1);
labelScore.textContent = originalScore;
}
display()
btnCheck.addEventListener('click', () => {
const numToBeChecked = Number(inputValue.value);
//In case user did not entered the value and clicked on check then we will show msg.
if(!numToBeChecked)
{
labelMsg.textContent = 'No number!';
}
else if(numToBeChecked === secretNum)
{
labelMsg.textContent = "Correct Number!";
labelSecretNum.textContent = secretNum;
btnCheck.style.display = "none";
}
else if(numToBeChecked > secretNum)
{
labelMsg.textContent = "Too high!";
}
else if(numToBeChecked < secretNum)
{
labelMsg.textContent = "Too low!";
}
setScore--;
labelScore.textContent = setScore;
if(setScore === 0)
{
btnCheck.style.display = "none";
}
});
btnAgain.addEventListener('click', () =>{
display()
setScore = originalScore;
});