-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
104 lines (94 loc) · 2.66 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
const books = [
[
"Genesis", "Exodus", "Leviticus", "Numbers", "Deuteronomy",
"Joshua", "Judges", "Ruth", "1 Samuel", "2 Samuel",
"1 Kings", "2 Kings", "1 Chronicles", "2 Chronicles", "Ezra",
"Nehemiah", "Esther", "Job", "Psalms", "Proverbs",
"Ecclasiastes", "Song of Solomon", "Isiah", "Jeremiah", "Lamentations",
"Ezekiel", "Daniel", "Hosea", "Joel", "Amos",
"Obadiah", "Jonah", "Micah", "Nahum", "Habakkuk",
"Zephaniah", "Haggai", "Zechariah", "Melachi"
],
[
"Matthew", "Mark", "Luke", "John", "Acts",
"Romans", "1 Corinthians", "2 Corinthians", "Galatians", "Ephesians",
"Philippians", "Colossians", "1 Thessalonians", "2 Thessalonians", "1 Timothy",
"2 Timothy", "Titus", "Philemon", "Hebrews", "James",
"1 Peter", "2 Peter", "1 John", "2 John", "3 John",
"Jude", "Revelation"
]
]
let score = 0
let time = 60
let rumble = ''
let book = ''
let id_answer = document.getElementById('answer')
let id_book = document.getElementById('book')
let id_button = document.getElementById('button')
let id_score = document.getElementById('score')
let id_timer = document.getElementById('timer')
function ongame(){
let random = Math.floor(Math.random() * books.length)
book = books[random][Math.floor(Math.random() * books[random].length)]
let i = []
for(let c = 0; c < book.length; c++){
let r = Math.floor(Math.random() * book.length)
if(i.includes(r)){
c--
}else{
i[c] = r
}
}
for(let c = 0; c < i.length; c++){
rumble += book[i[c]]
}
id_book.textContent = 'Rumbled letters: ' + rumble.replace(/\s/g, '').toLowerCase()
id_answer.style.display = 'inline'
id_button.textContent = 'Send Answer'
}
id_button.addEventListener('click', () => {
sendAnswer()
})
id_answer.addEventListener('keyup', (event) => {
if(event.keyCode === 13){
sendAnswer()
}
})
function sendAnswer(){
if (rumble != '') {
if (id_answer.value == book) {
score++
} else {
score--
}
} else {
timer()
}
rumble = ''
id_answer.value = ''
id_score.textContent = 'Your current score: ' + score
ongame()
}
function timer(){
if(time > 0){
time--
id_timer.textContent = 'Time: ' + time
setTimeout(timer, 1000)
}else{
id_answer.value = ''
id_answer.style.display = 'none'
id_button.style.display = 'none'
id_book.textContent = "Time's up!"
setTimeout(() => {
id_button.style.display = 'inline'
id_button.textContent = 'Initiate Game'
book = ''
rumble = ''
score = 0
time = 60
}, 5000)
}
}
document.getElementById('hide').addEventListener('click', () => {
document.getElementById('tutorial').style.display = 'none'
})