-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
79 lines (73 loc) · 2.07 KB
/
Copy pathmain.js
File metadata and controls
79 lines (73 loc) · 2.07 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
var quizdata = [
{
question:'Which framework is related to JavaScript?',
a:'.NET',
b:'flask',
c:'react',
d:'django',
correct:'c'
},
{
question:'Which is not a programming language?',
a:'html',
b:'python',
c:'java',
d:'js',
correct:'a'
},
{
question:'Which is not a framework?',
a:'react',
b:'javascript',
c:'angular',
d:'django',
correct:'b'
},
{
question:'css stands for',
a:'cascading style state',
b:'cascading style sheet',
c:'cascading sheet of style',
d:'none',
correct:'b'
}
];
var quiz = document.getElementById("quizdiv");
var answer = document.querySelectorAll('.answer');
var question = document.getElementById('question');
var option_a= document.getElementById('a_value');
var option_b= document.getElementById('b_value');
var option_c= document.getElementById('c_value');
var option_d= document.getElementById('d_value');
var submitbtn = document.getElementById('submit');
var currentQuestion = 0;
var quizScore = 0;
loadQuiz();
function loadQuiz(){
deselect();
question.innerHTML=quizdata[currentQuestion].question;
option_a.innerText=quizdata[currentQuestion].a;
option_b.innerText=quizdata[currentQuestion].b;
option_c.innerText=quizdata[currentQuestion].c;
option_d.innerText=quizdata[currentQuestion].d;
}
function deselect(){
answer.forEach(answer=>answer.checked=false);
}
submitbtn.addEventListener('click',()=>{
var selectedoption;
answer.forEach(answer=>{
if(answer.checked){
selectedoption = answer.id;
}
});
if(selectedoption == quizdata[currentQuestion].correct){
quizScore++;
}
currentQuestion=currentQuestion+1;
if(currentQuestion>=quizdata.length){
quiz.innerHTML = `<h1>You have answered ${quizScore} correctly out of ${quizdata.length}</h1>`;
}else{
loadQuiz();
}
});