-
Notifications
You must be signed in to change notification settings - Fork 0
/
cbt.js
70 lines (69 loc) · 1.61 KB
/
cbt.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
let cbtQue = [
{
que: "What is your fav food",
opt: ['Eba', 'Amala', 'Iyan', 'Fufu'],
corrAns: 'Iyan'
},
{
que: "What is your fav color",
opt: ['Red', 'Pink', 'White', 'Yellow'],
corrAns: 'Red'
},
{
que: "What is your fav Car",
opt: ['Jeep', '501', 'VoVo', 'Benz'],
corrAns: '501'
},
{
que: "What is your fav school",
opt: ['OIL', 'APC', 'NMP', 'SQI'],
corrAns: 'SQI'
},
{
que: "What is your fav city",
opt: ['Abuja', 'Aba', 'Ibadan', 'New York'],
corrAns: 'New York'
},
];
let sel_ans = [];
let index = 0;
let screen = document.getElementById("screen");
Array.push ('')
function showQue() {
screen.innerHTML = `
<h1>${index}. ${cbtQue[index].que}</h1>
`
cbtQue[index].opt.forEach((el) => {
let opts = sel_ans
if (sel_ans[index] == opts) {
screen.innerHTML += `
<input checked onclick="selected('${el}')" name='ans' type='radio' />
<label>${el}</label> <br>
`
} else {
screen.innerHTML += `
<input onclick="selected('${el}')" name='ans' type='radio' />
<label>${el}</label> <br>
`
}
})
}
showQue()
function next() {
index++;
showQue()
if (index == 4){
index = 0;
}
}
function prev() {
if (index == 0){
index = 4;
}
index--;
showQue()
}
function selected(element){
// console.log(element);
console.log(sel_ans);
}