-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
130 lines (104 loc) · 2.27 KB
/
main.js
File metadata and controls
130 lines (104 loc) · 2.27 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
const QA = document.querySelector(".question")
const cont = document.querySelector(".container")
const A = document.querySelector(".A")
const B = document.querySelector(".B")
const C = document.querySelector(".C")
const D = document.querySelector(".D")
const btn = document.querySelector(".btn-ans")
const answEls = document.querySelectorAll(".Answer");
const quiz =[
{
question: "Who was the first president of kenya?",
a:"Jomo kenyatta",
b:"Musalia Mudavadi",
c:"Uhuru kenyatta",
d:"Raila odinga",
correct:"a"
},
{
question: "What is the capital city of kenya",
a:"Nairobi",
b:"Turkana",
c:"Kajiado",
d:"Kiambu",
correct:"a"
}
,
{
question: "Which country borders kenya to the north ?",
a:"Somalia",
b:"Uganda",
c:"Ethiopia",
d:"Tanzania",
correct:"c"
}
,
{
question: "Which is kenya's most popular tourist attraction?",
a:"Sandy beaches",
b:"Culture",
c:"Cuisines",
d:"Wildlife",
correct:"d"
}
,
{
question: "What is the staple food of kenya?",
a:"Pilau",
b:"Ugali",
c:"Nyama choma",
d:"Chapati",
correct:"b"
}
,
{
question: "When did kenya gain independence ?",
a:"1970",
b:"1964",
c:"1999",
d:"2015",
correct:"b"
}
]
let k = 0;
let score = 0;
function quizQ(){
QA.innerText = quiz[k].question;
A.innerText = quiz[k].a
B.innerText = quiz[k].b
C.innerText = quiz[k].c
D.innerText = quiz[k].d
}
quizQ()
let final;
function selected(){
answEls.forEach(element => {
if(element.checked == true){
final = element.id
return final; }
})};
function scores(){
if(final === quiz[k].correct){
if(score < 7){
score++;
}
console.log(score); }
}
function deselected(){
answEls.forEach(element => {
element.checked = false;
});
}
function submit(){
selected()
scores()
console.log(final);
if(k < quiz.length-1){
k++;
quizQ()
deselected()
}
else{
cont.innerHTML = `<h2> You got ${score}/6 questions </h2> <button onclick="location.reload()" id="btn2">Restart</button>`;
}
}