-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
100 lines (84 loc) · 2.6 KB
/
app.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
const quizDB =[
{
question : " Q1: What is the full form of HTML ?",
a: "Hello To My Land",
b: "Hey Text Markup Language",
c: "Hypertext Makeup Language",
d: "Hypertext Markup Language",
ans: "ans4"
} ,
{
question : "Q2: Wgat is the full form of CSS ? ",
a: "Cascading Style Sheets",
b: "Cascading Style Sheep",
c: "Cartoon Style Sheets",
d: "Cascading Super Sheets",
ans:"ans1"
},
{
question :"Q3: Wgat is the full form of HTTP ?",
a: "Hypertext Transfer Product ",
b: "Hypertext Test Protocol",
c: "Hey Transfer Protocol",
d: "Hypertext Transfer Protocol",
ans:"ans4"
},
{
question : "Q4: What is the full form of JS ?",
a: "JavaScript",
b: "JavSuper",
c: "JustScript",
d: "JordenShoes",
ans: "ans1"
}
];
const question =document.querySelector('.question');
const option1 =document.querySelector('#option1');
const option2 =document.querySelector('#option2');
const option3 =document.querySelector('#option3');
const option4 =document.querySelector('#option4');
const submit = document.querySelector('#submit');
const answers= document.querySelectorAll('.answer');
const showScore=document.querySelector('#showScore');
let questionCount=0;
let score=0;
const loadQuestion=()=>{
const questionList = quizDB[questionCount];
question.innerText = questionList.question;
option1.innerText = questionList.a;
option2.innerText = questionList.b;
option3.innerText = questionList.c;
option4.innerText = questionList.d;
}
loadQuestion();
const getCheckAnswer=()=>{
let answer;
answers.forEach((curAnsElem)=>{
if(curAnsElem.checked){
answer= curAnsElem.id;
}
});
return answer;
};
const deselectAll = () => {
answers.forEach((curAnsElem)=> curAnsElem.checked = false);
}
submit.addEventListener('click',()=>{
const checkedAnswer = getCheckAnswer();
console.log(checkedAnswer);
if(checkedAnswer === quizDB[questionCount].ans){
score++;
}
questionCount++;
deselectAll();
if(questionCount <quizDB.length){
loadQuestion();
}
else{
showScore.innerHTML = `
<h3> You scored ${score}/${quizDB.length} </h3>
<button class="btn" onclick="location.reload()">Play Again</button>
` ;
showScore.classList.remove('scoreArea');
}
});