-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
375 lines (279 loc) · 8.58 KB
/
Copy pathapp.js
File metadata and controls
375 lines (279 loc) · 8.58 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
const some = document.querySelector(".some");
const main = document.querySelector(".main");
const question = document.querySelector(".question");
const options = document.querySelectorAll(".options li")
const list = document.querySelector('.opt ul');
const score = document.querySelector('.top');
const select = document.querySelector('.select');
const other = document.querySelector('select');
let questions = ["what year did Nigeria get their independence","what is the square root of 25", "how many legs has a cow","what is the capital of Nigeria","Nigeria’s current president","What was the first political party in Nigeria?","Who was the first female vice chancellor in Nigerian university?"," Who was the first woman to buy a car in Nigeria?","Nigeria is divided into how many geopolitical zones?"];
let sample = [[1960,1940,1860,1820], [3,20,5,15], [2,4,6,3],['Anambra', 'Abuja', 'Benin', 'lagos'],["Muhammadu Buhari","Wole Soyinka","Pete Obi", "Atiku Abubakar"],["Nigerian National Democratic party (NNDP)","peoples democratic party (PDP)","All peoples Grand Aliance (APGA)","Sure boys party (SB)"],["Chimamanda Ngozi Adichie","Grace Alele Williams","Florence Ita Giwa","Funmi Iyanda"],["Florence Ita Giwa","Funmi Iyanda","Funmilayo Ransome Kuti","Folake Coker"],["Six (6) geopolitical zones","Seven (7) geopolitical zones","Five (5) geopolitical zones","Eight (8) geopolitical zones"],["Decision support system","Collaboration system","Management information system","Transaction processing system"]];
let answer = [1960,5,4,'Abuja',"Muhammadu Buhari","Nigerian National Democratic party (NNDP)","Grace Alele Williams","Funmilayo Ransome Kuti","Six (6) geopolitical zones"];
let math = ["what is the square root of 25", "how many legs has a cow"];
let Manswer = [5,4,];
let Msample = [[3,20,5,15], [2,4,6,3]];
function shufful(sample){
sample.sort(() => {
return Math.random() - 0.5
})
}
let x
let num = []
let s = 0;
let restart;
function generate(){
x = Math.floor(Math.random() * 9);
}
function clear(){
question.textContent = ""
options.textContent = ""
s = 0;
num = []
score.textContent = `Score : ${s}`
}
function populate(){
let counter = 0;
generate()
if (num.includes(x,0) == true){
populate()
}else if (other.value == "Random"){
shufful(sample[x])
num.push(x)
question.textContent = questions[x];
for(let i = 0; i <= sample[x].length; i++){
options[counter].textContent = sample[x][i];
counter++
}
} else{
alert("only Random is supported for now")
select.style.display = "block";
main.style.display = "none";
clear()
}
}
some.addEventListener("click", (e) => {
t = 0;
select.style.display = "none";
main.style.display = "block";
tic.style.display = "none";
populate()
})
list.addEventListener("click", (e) => {
if(e.target.textContent == answer[x]){
e.target.style.background = 'green'
s++
score.textContent = `Score : ${s}`
setTimeout(() => {
e.target.style.background = ""
populate()
}, 500)
}else{
e.target.style.background = 'red'
setTimeout(() => {
e.target.style.background = ""
restart = confirm("Game over do you want to play again?")
if(restart == true){
clear()
}else{
select.style.display = "block";
main.style.display = "none";
clear()
}
populate()
}, 500)
}
})
const start = document.querySelector("#btn");
const restarts = document.querySelector("#btn1");
const table = document.querySelector(".tables");
const tt = document.querySelectorAll(".tables tr td");
const tic = document.querySelector('.Tic');
const ttt = document.querySelector('.ttt');
const scores = document.querySelector('.score');
const se = document.querySelector('.op');
let counter = 0;
let xScore = 0;
let oScore = 0;
let arr;
function check(){
arr = [];
tt.forEach((e) => {
arr.push(e.textContent);
})
console.log(arr);
let row1 = "";
let row2 = ""
let row3 = ""
for (let i = 0; i < 3; i++){
row1 += arr[i];
}
for (let i = 3; i < 6; i++){
row2 += arr[i]
}
for (let i = 6; i < 9; i++){
row3 += arr[i]
}
row1 == "XXX" ? xWins() : row1 == "OOO" ? oWins() : "ww"
row3 == "XXX" ? xWins() : row3 == "OOO" ? oWins() : "ww"
row2 == "XXX" ? xWins() : row2 == "OOO" ? oWins() : "ww"
let column1 = "";
let column2 = ""
let column3 = ""
for (let i = 0; i < arr.length; i+=3){
column1 += arr[i];
}
for (let i = 1; i < arr.length; i+= 3){
column2 += arr[i]
}
for (let i = 2; i < arr.length; i+=3){
column3 += arr[i]
}
column1 == "XXX" ? xWins() : column1 == "OOO" ? oWins() : "ww"
column2 == "XXX" ? xWins() : column2 == "OOO" ? oWins() : "ww"
column3 == "XXX" ? xWins() : column3 == "OOO" ? oWins() : "ww"
let l = "";
let o = ""
for (let i = 0; i < arr.length; i+=4){
l += arr[i];
}
for (let i = 2; i < arr.length; i+= 2){
o += arr[i]
}
l == "XXX" ? xWins() : l == "OOO" ? oWins() : "ww"
o == "XXX" ? xWins() : o == "OOO" ? oWins() : "ww"
}
let ag;
function oWins(){
oScore++
scores.textContent = `X-Score : ${xScore} O-Score : ${oScore}`
ag = confirm("O wins would you like another round")
if (ag == true){
counter = 0;
tt.forEach((t)=>{
t.textContent = "";
})
input()
}else{
select.style.display = "block";
main.style.display = "none";
tic.style.display = "none";
}
}
function xWins(){
xScore++
scores.textContent = `X-Score : ${xScore} O-Score : ${oScore}`
ag = confirm("X wins would you like another round")
if (ag == true){
counter = 0;
tt.forEach((t)=>{
t.textContent = "";
})
input()
}else{
select.style.display = "block";
main.style.display = "none";
tic.style.display = "none";
}
}
x = 0;
let a;
let y
function input(e){
x = 0
if (e.target.textContent == ""){
if (counter % 2 == 0 && counter < 9){
e.target.textContent = 'X'
}else if (counter % 2 != 0 && counter < 9){
e.target.textContent = 'O'
}else{
alert('Game Over')
}
counter++
check()
}
tt.forEach((t)=>{
if(t.textContent == ""){
console.log(t.textContent)
x++
}
})
console.log(x)
if(x == 0){
a = confirm("draw...Again??")
if (a == true){
counter = 0;
tt.forEach((t)=>{
t.textContent = "";
})
input()
}else{
select.style.display = "block";
main.style.display = "none";
tic.style.display = "none";
}
}
}
ttt.addEventListener("click", (e) => {
if (se.value == "multiPlayer"){
tt.forEach((t)=>{
t.textContent = "";
})
counter = 0;
xScore = 0;
oScore = 0;
scores.textContent = `X-Score : ${xScore} O-Score : ${oScore}`
select.style.display = "none";
main.style.display = "none";
tic.style.display = "block";
console.log("...")
table.addEventListener("click", input)
}else{
onePlayer()
}
})
restarts.addEventListener("click", (e)=>{
tt.forEach((t)=>{
t.textContent = "";
})
a = ""
counter = 0;
xScore = 0;
oScore = 0;
scores.textContent = `X-Score : ${xScore} O-Score : ${oScore}`
})
// Single Player Mode
function onePlayer(){
counter = 0;
xScore = 0;
oScore = 0;
scores.textContent = `X-Score : ${xScore} O-Score : ${oScore}`
select.style.display = "none";
main.style.display = "none";
tic.style.display = "block";
table.addEventListener("click", ai)
}
restarts.addEventListener("click", onePlayer)
let ano
function ai(e){
arr = [];
ano = []
if (e.target.textContent == ""){
e.target.textContent = "X"
}
tt.forEach((e) => {
arr.push(e.textContent);
})
console.log(arr);
for(let i = 0; i < tt.length; i++){
if(tt[i].textContent == "X"){
ano.push(i)
}
}
y = Math.floor(Math.random() * tt.length);
if (ano.includes(y,0)){
y = Math.floor(Math.random() * tt.length);
ai()
}
tt[y].textContent = "O"
check()
}