-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile.js
114 lines (89 loc) · 3.08 KB
/
file.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
104
105
106
107
108
109
const questions = [
{
question:"How old am I ?" ,
answer1 : 22 ,
answer2 : 19 ,
answer3 : 30 ,
answer4 : 24 ,
correct : "answer4"
},
{
question:"What does HTML stand for ?" ,
answer1 : "Hyper Text Markup Language" ,
answer2 : "Hyper Links Markup Language" ,
answer3 : "Programming Language" ,
answer4 : "Home Tool Markup Language" ,
correct : "answer1"
},
{
question:"Who is making the Web standards ?" ,
answer1 : "Mozilla" ,
answer2 : "The World Wide Web Consortium" ,
answer3 : "Google" ,
answer4 : "Microsoft" ,
correct : "answer2"
},
{
question:"Choose the correct HTML element for the largest heading: ?" ,
answer1 :"<Heading>",
answer2 : "<h6>" ,
answer3 : "<head>" ,
answer4 : "<h1>" ,
correct : "answer4"
},
] ;
let currentquestion = 0 ;
let answer = undefined ;
let score = 0 ;
window.onload = function (){
document.getElementById('questionEl').innerText = questions[currentquestion].question
document.getElementById('oneAnswer').innerText = questions[currentquestion].answer1
document.getElementById('twoAnswer').innerText = questions[currentquestion].answer2
document.getElementById('threeAnswer').innerText = questions[currentquestion].answer3
document.getElementById('fourAnswer').innerText = questions[currentquestion].answer4
}
document.getElementById('submit').addEventListener('click' , () => {
//check to see the answer
let check = checkQuestion();
console.log(check)
if(check){
if(check === questions[currentquestion].correct){
score++;
unselect();
} else {
unselect()
}
console.log(score)
currentquestion++;
if (currentquestion < questions.length){
document.getElementById('questionEl').innerText = questions[currentquestion].question
document.getElementById('oneAnswer').innerText = questions[currentquestion].answer1
document.getElementById('twoAnswer').innerText = questions[currentquestion].answer2
document.getElementById('threeAnswer').innerText = questions[currentquestion].answer3
document.getElementById('fourAnswer').innerText = questions[currentquestion].answer4
} else if (score > 2){
alert(`Good you finished the quiz with respectful score ${score}`);
console.log('You finished the quiz')
} else {
alert(` Hard luck your score is ${score}`)
}
}
});
function checkQuestion(){
const answerEls = document.querySelectorAll('.answer-el');
// a <== Answers inside answer
let answer ;
answerEls.forEach((a) => {
if(a.checked){
answer = a.id ;
}
});
return answer
}
function unselect(){
const answerEls = document.querySelectorAll('.answer-el');
// a <== Answers inside answer
answerEls.forEach((a) => {
a.checked = false;
});
}