-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
111 lines (109 loc) · 3.65 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// initialising variables
var time = 30
var liflines = 10
var ans
var operations = ["+", "-", "*"]
// showing the content to the screen
function show() {
setInterval(() => {
time -= 1
document.getElementById('time').innerHTML = time
}, 1000)
liflines = localStorage.getItem("lifelines") || 10
localStorage.setItem("lifelines", liflines)
document.getElementById("lifeline").innerHTML = localStorage.getItem("lifelines") || 10
var first = Math.ceil(Math.random() * 50) + 1
var sec = Math.ceil(Math.random() * 50) + 1
var op = Math.floor(Math.random() * 3)
document.getElementById("firstNum").innerHTML = first
document.getElementById("secondNum").innerHTML = sec
document.getElementById("operation").innerHTML = operations[op]
ans = `${first} ${operations[op]} ${sec}`
console.log(eval(ans));
}
show()
// checkinng the submitted answer
function check(ans) {
if (liflines > 0) {
if (time > 0) {
if (document.getElementById("answer").value.length > 0) {
if (document.getElementById("answer").value == ans) {
liflines = Number(liflines) + 1
localStorage.setItem("lifelines", liflines)
Swal.fire('Correct Answer', '', 'success').then(()=>{
location.reload()
})
}
else {
liflines -= 1
localStorage.setItem("lifelines", liflines)
Swal.fire('Wrong', `The Correct answer was ${eval(ans)}`, 'error').then(()=>{
location.reload()
})
}
}
else {
Swal.fire('Type Something', '', 'info')
}
}
else {
Swal.fire('Time is Over', '', 'info')
}
}
else {
Swal.fire('Life Lines Finished', 'Got no more Life line Get some by watching ad', 'info')
}
}
// adding skip functionality
function skip() {
if (liflines > 0) {
liflines -= 1
localStorage.setItem("lifelines", liflines)
location.reload()
}
else {
Swal.fire('Life Lines Finished', 'Got no more Life line Get some by watching ad', 'info')
}
}
// upgrading lifeline by shoing ad
function upd() {
if (liflines < 5) {
let timerInterval
Swal.fire({
title: 'Dont Close',
html: 'You will be rewarded in <b></b> seconds.',
timer: 2000,
timerProgressBar: true,
didOpen: () => {
Swal.showLoading()
const b = Swal.getHtmlContainer().querySelector('b')
timerInterval = setInterval(() => {
b.textContent = Swal.getTimerLeft() / 1000
}, 100)
},
willClose: () => {
clearInterval(timerInterval)
}
}).then((result) => {
if (result.dismiss === Swal.DismissReason.timer) {
localStorage.setItem("lifelines", 10)
Swal.fire('+10', 'Life line increased successfully', 'success').then(() => {
location.reload()
})
}
})
}
else{
Swal.fire('You Still Have Them', 'You can only use this option once your lifeline gets below 5', 'info')
}
}
// checking over time
function checkTime() {
if (time <= 0) {
time = 30
Swal.fire('Time is Over', '', 'info').then(() => {
location.reload()
})
}
}
setInterval(checkTime, 1000)