-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
84 lines (74 loc) · 1.94 KB
/
main.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
const answer = document.querySelector("#answer")
const inputQuestion = document.querySelector("#inputQuestion")
const askButton = document.querySelector('#askButton')
const triangle = document.querySelector('#triangle')
const control = document.querySelector('#control')
const audio = document.querySelector('#audio')
const answers = [
"It is certain",
"It is decidedly so",
"Without a doubt",
"Yes, definitely",
"You may rely on it",
"As I see it, yes",
"Most likely",
"Outlook good",
"Yes",
"Signs point to yes",
"Reply hazy, try again",
"Ask again later",
"Better not tell you now",
"Cannot predict now",
"Concentrate and ask again",
"Don't count on it",
"My reply is no",
"My sources say no",
"Outlook not so good",
"Very doubtful",
]
function ask() {
if(inputQuestion.value == "") {
inputQuestion.placeholder='Type your question!'
inputQuestion.classList.add('error')
setTimeout(function() {
inputQuestion.classList.remove('error')
}, 750)
return
}
askButton.classList.add('hide')
askButton.setAttribute("disabled", true)
inputQuestion.classList.add('hide')
answer.innerHTML = answers[Math.floor(Math.random() * answers.length)]
answer.classList.add('show')
triangle.classList.add('show')
setTimeout(function() {
askButton.classList.remove('hide')
askButton.removeAttribute("disabled")
inputQuestion.classList.remove('hide')
triangle.classList.remove('show')
answer.classList.remove('show')
inputQuestion.value = ""
inputQuestion.placeholder='Ask me anything...'
}, 2000)
}
let a=1;
let b=0;
askButton.addEventListener("click", function() {
if(a == 1 && b == 0) {
audio.play()
b++
a--
} return
});
control.addEventListener("click", function() {
if(a == 0) {
audio.pause()
a++
control.style.opacity="0.6"
} else {
audio.play();
a--
b++
control.style.opacity="1"
}
});