-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
62 lines (56 loc) · 2 KB
/
Copy pathscript.js
File metadata and controls
62 lines (56 loc) · 2 KB
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
const btn = document.querySelector('#startBtn')
const checkbtn = document.querySelector('#nextBtn')
const alert = document.querySelector('#success')
let chance = 5
let randomNumber
checkbtn.addEventListener('click', function () {
checkGuess()
})
document.querySelector('#guess').addEventListener('keydown', function (event) {
if (event.key === 'Enter') {
checkGuess()
}
})
console.log(btn.textContent)
btn.addEventListener('click', function () {
alert.style.display = 'none'
document.querySelector('.view').style.display = 'block'
document.querySelector('#startBtn').style.display = 'none'
randomNumber = Math.floor(Math.random() * 100) + 1
console.log('Num Generated : ' + randomNumber)
chance = 5
})
let zero = 0
function checkGuess() {
const userGuess = parseInt(document.querySelector('#guess').value)
chance--
if (userGuess == randomNumber) {
document.querySelector('#guess').value = ''
console.log('You Win')
document.querySelector('.view').style.display = 'none'
document.querySelector('#startBtn').style.display = 'block'
alert.style.display = 'block'
alert.textContent = `${userGuess} is Correct You Win !!!`
alert.className = 'alert alert-success'
win()
} else if (userGuess < randomNumber) {
document.querySelector('#guess').value = ''
console.log('Too low')
alert.style.display = 'block'
alert.textContent = `${userGuess} is Too low , ${chance} chance left`
alert.className = 'alert alert-warning'
} else if (userGuess > randomNumber) {
document.querySelector('#guess').value = ''
console.log('Too high')
alert.style.display = 'block'
alert.textContent = `${userGuess} is Too High , ${chance} chance left`
alert.className = 'alert alert-warning'
}
if (chance === 0) {
document.querySelector('.view').style.display = 'none'
document.querySelector('#startBtn').style.display = 'block'
alert.style.display = 'block'
alert.textContent = 'You Lost All Chances !!!'
alert.className = 'alert alert-danger'
}
}