-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScript.js
195 lines (180 loc) · 4.98 KB
/
Script.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
const quiz= [
{
Question : "Q1: Which animal lays eggs?",
n:"Question 1 0f 10",
a : "Dog",
b : "Cat",
c : "Duck",
d : "Sheep",
ans:"ans3"
},
{
Question : "Q2: A male cow is called?",
n:"Question 2 0f 10",
a : "Ox",
b : "Dog",
c : "Sheep",
d : "Monkey",
ans :"ans1"
},
{
Question : "Q3: Which one is a fur-bearing animal?",
n:"Question 3 0f 10",
a : "Hens",
b : "crocodile",
c : "Tortories",
d : "cat",
ans :"ans4"
},
{
Question : "Q4: What is Earth’s only natural satellite?",
n:"Question 4 0f 10",
a : "Sun",
b : "Mars",
c : "Venus",
d : "Moon",
ans :"ans4"
},
{
Question : "Q5: What part of the body helps you move?",
n:"Question 5 0f 10",
a : "Eyes",
b : "Lungs",
c : "Pancreas",
d : "Muscles",
ans :"ans4"
},
{
Question : "Q6: The two holes of the nose are called?",
n:"Question 6 0f 10",
a : "Eyelids",
b : "Nostrils",
c : "Nails",
d : "Hairs",
ans :"ans2"
},
{
Question : "Q7: What star shines in the day and provides light?",
n:"Question 7 0f 10",
a : "Moon",
b : "Venus",
c : "sun",
d : "Mars",
ans :"ans3"
},
{
Question : "Q8: Which organ covers the entire body and protects it?",
n:"Question 8 0f 10",
a : "Liver",
b : "Heart",
c : "Skin",
d : "Brain",
ans :"ans3"
},
{
Question : "Q9: Which shape is a round?",
n:"Question 9 0f 10",
a : "RECANTLE",
b : "CIRCLE",
c : "RHOMBUS",
d : "SQUARE",
ans :"ans2"
},
{
Question : "Q10: What is the young one of a cow called?",
n:"Question 10 0f 10",
a : "Puppy",
b : "kitten",
c : "calf",
d : "Baby",
ans :"ans3"
}
];
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 progress =document.querySelector('#progress')
const answers = document.querySelectorAll('.answer');
const showscore = document.querySelector('#showscore');
const Next = document.querySelector('#next');
const Previous = document.querySelector('#previous');
let questionCount =0;
let score =0;
const loadQuestion = () => {
const questionlist=quiz[questionCount];
question.innerText=questionlist.Question;
progress.innerHTML=questionlist.n;
option1.innerText = questionlist.a;
option2.innerText = questionlist.b;
option3.innerText = questionlist.c;
option4.innerText = questionlist.d;
}
loadQuestion();
const GetcheckAns = () =>{
let answer;
answers.forEach((currelemt) =>{
if(currelemt.checked){
answer = currelemt.id;
}
});
return answer;
}
const deselectall = () =>{
answers.forEach((currelemt) => currelemt.checked=false);
}
Next.addEventListener('click',() =>{
questionCount++;
deselectall();
if(questionCount < quiz.length){
loadQuestion();
}
else{
showscore.innerHTML=`<h3> you Scored ${score}/${quiz.length}</h3>
<button class="btn" onclick ="location.reload()"> Play Again ✌</button>`;
showscore.classList.remove('socrearea');
}
})
Previous.addEventListener('click',() =>{
questionCount--;
// deselectall();
if(questionCount >= 0){
loadQuestion();
}
})
submit.addEventListener('click' ,() =>{
const checkedAns= GetcheckAns();
console.log(checkedAns);
if(checkedAns === quiz[questionCount].ans){
score++;
};
questionCount++;
deselectall();
{
showscore.innerHTML=`<h3> you Scored ${score}/${quiz.length}</h3>
<button class="btn" onclick ="location.reload()"> Play Again ✌</button>`;
showscore.classList.remove('socrearea');
clearInterval(myt);
}
});
const quiztimeinMin=10;
let time=quiztimeinMin*60;
let counting = document.getElementById('countdown');
let stopinterval=document.getElementById('submit')
const myt= setInterval(updateCountdown,1000);
function updateCountdown(){
const minute=Math.floor(time/60);
let seconds = time % 60;
counting.innerHTML=`${minute}: ${seconds}`;
time--;
if(time<0){
clearInterval(myt);
counting.style.innerHTML='00:00';
submit.click();
showscore.innerHTML=`<h3> you Scored ${score}/${quiz.length}</h3>
<button class="btn" onclick ="location.reload()"> Play Again ✌</button>`;
showscore.classList.remove('socrearea');
}
}