-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
58 lines (44 loc) · 1.28 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const input = document.querySelector('#guess')
const button = document.querySelector('#btn')
const answer = Math.floor(Math.random()*20)+1;
input.addEventListener('keypress', function(e){
if (e.keyCode === 13)
play()
})
button.addEventListener ( 'click', play);
function play(){
const userNumber = document.querySelector('#guess').value;
if (userNumber < 1 || userNumber > 20) {
Swal.fire({
icon: 'error',
title: 'Oops...',
text: 'Must be a number between 1 and 20!',
})
}
else if (isNaN(userNumber)){
Swal.fire({
icon: 'error',
title: 'Oops...',
text: 'Must be a number between 1 and 20!',
})
}
else{
if(userNumber < answer) {
// alert ('Higher!')
Swal.fire('Higher!')
}
else if (userNumber> answer) {
Swal.fire('Lower!')
}
else {
Swal.fire({
title: 'Correct!',
text: 'Congratulations!!!',
imageUrl: 'https://www.cardmessages.com/files/impressive-but-not-surprising-congratulations.jpg',
imageWidth: 400,
imageHeight: 200,
imageAlt: 'Custom image',
});
}
}
}