-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.js
63 lines (52 loc) · 1.68 KB
/
bot.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
const question = document.getElementById("question")
const answer = document.getElementById("answer")
const loaders = document.getElementById("loaders")
const container = document.getElementsByClassName("container")
let init = 0
const botSay = (data) => {
return [
"Im dausBot here, what is your name?",
`Hello ${data?.nama}. How old are you?`,
`I see.. ${data?.umur} is still a young age hehe. What is your hobby?`,
`Wow, me too. ${data?.hobi} is also my hobby. Whats your job?`,
`Nice, i hope to work as ${data?.kerja} too. Ok till we meet again ya?`
]
}
question.innerHTML = botSay()[0]
let userData = []
function botStart() {
if (answer.value.length <1) return alert("Fill in the answer first")
init++
if (init===1) {
botDelay({nama: answer.value})
}else if (init===2){
botDelay({umur: answer.value})
}else if (init===3){
botDelay({hobi: answer.value})
}else if (init==4){
botDelay({kerja: answer.value})
}else if (init===5){
finishing()
}else {
botEnd()
}
}
function botDelay(userAnswer) {
loaders.style.display = "block"
container[0].style.filter = "blur(8px)"
setTimeout(() => {
question.innerHTML = botSay(userAnswer)[init]
loaders.style.display = "none"
container[0].style.filter = "none"
}, [1000])
userData.push(answer.value)
answer.value = ""
}
function finishing() {
question.innerHTML = `Thank you ${userData[0]} for using me, we can play ${userData[2]} together later`
answer.value = "You are welcome!"
}
function botEnd() {
alert("Thank you, the window will be reloaded")
window.location.reload()
}