forked from sadiqshah786/Quiz-App
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
338 lines (305 loc) · 8.92 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
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
var quizQuestions = [
{
question: "Q1 : Inside which HTML element do we put the JavaScript?",
a: " <javascript>",
b: " <script>",
c: " <scripting>",
d: " <js>",
ans: "ans2"
},
{
question: "Q2 : adding or removing the elements from any index by",
a: "slice",
b: 'push',
c: "splice",
d: "a & b",
ans: "ans3"
}
,
{
question: "Q3 : Where is the correct place to insert a JavaScript?",
a: "body",
b: "head",
c: "div",
d: "a & b",
ans: "ans1"
}
,
{
question: "Q4 : if a=5; so ++a + a++ ?",
a: "10",
b: "6",
c: "8",
d: "12",
ans: "ans4"
}
,
{
question: "Q5 : if(a>b) complete the code",
a: "{",
b: "}",
c: "{ code of block }",
d: "if else",
ans: "ans3"
}
,
{
question: "Q6 : Which of the below is used in Java script to insert special characters?",
a: "&",
b: ".",
c: "{ ",
d: "\\",
ans: "ans4"
}
,
{
question: "Q7 : JavaScript ignores extra spaces",
a: "True",
b: "False",
c: "a & b",
d: "Not Mentioned",
ans: "ans2"
}
,
{
question: "Q8 : Which is the correct way to write a JavaScript array?",
a: 'var txt = new Array(1:"arr",2:"kim",3:"jim")',
b: 'var txt = new Array:1=(" arr ")2=("kim")3=("jim")',
c: 'var txt = new Array("arr ","kim","jim")',
d: 'var txt = new Array=" arr ","kim","jim"',
ans: "ans3"
}
,
{
question: "Q9 : 3 > 2 === false;",
a: "True",
b: "False",
c: "a & b",
d: "Not Mentioned",
ans: "ans2"
}
,
{
question: "Q10 : JavaScript is a ___ -side programming language.",
a: " Client",
b: "Server",
c: "a & b",
d: "None of the above",
ans: "ans3"
}
,
{
question: "Q11 : Which of the following is not a valid JavaScript variable name?",
a: "2java ",
b: "_java_and_ java _names",
c: "a & b",
d: "javaandjava",
ans: "ans1"
}
,
{
question: "Q12: What language defines the behavior of a web page?",
a: " HTML ",
b: " CSS ",
c: "XML",
d: "Java Script",
ans: "ans4"
}
,
{
question: "Q13 : Is it possible to declare a variable in Java Script along its type?",
a: " Yes ",
b: " No ",
c: "May be",
d: "Not sure",
ans: "ans1"
}
,
{
question: "Q14 : Java Script supports all boolean operators",
a: "True",
b: "False",
c: "a & b",
d: "Not Mentioned",
ans: "ans2"
}
,
{
question: "Q15 : removed elements, splice returns",
a: "removed value",
b: "length",
c: "array",
d: "a & b",
ans: "ans1"
}
,
{
question: "Q16 : Select the Sir Ghous Ahmed var teachers = ['Sir Haider Ali', 'Sir Ghous Ahmed','Sir Kashif Sulmeman','Sir Salman Zafar']",
a: "teachers.slice(0,1)",
b: "teachers.slice(2,3)",
c: "teachers.slice(3,)",
d: "teachers.slice(1,2)",
ans: "ans4"
}
,
{
question: "Q17 : Push and Unshift return" ,
a: "value",
b: "length",
c: "whole array",
d: "not sure",
ans: "ans2"
}
,
{
question: "Q18 : var teachers = ['Sir Haider Ali', 'Sir Ghous Ahmed','Sir Kashif Sulmeman','Sir Salman Zafar'] teachers.splice(2,0,'Sir Rizwan Jamal')" ,
a: "['Sir Haider Ali', 'Sir Ghous Ahmed', 'Sir Rizwan Jamal', 'Sir Kashif Sulmeman', 'Sir Salman Zafar']",
b: "['Sir Haider Ali', 'Sir Rizwan Jamal','Sir Ghous Ahmed', 'Sir Kashif Sulmeman', 'Sir Salman Zafar']",
c: "['Sir Haider Ali', 'Sir Ghous Ahmed', 'Sir Kashif Sulmeman', 'Sir Rizwan Jamal','Sir Salman Zafar']",
d: "['Sir Rizwan Jamal',Sir Haider Ali', 'Sir Ghous Ahmed', 'Sir Kashif Sulmeman', 'Sir Salman Zafar']",
ans: "ans1"
}
,
{
question: 'Q19 :Which are the correct “if” statements to execute certain code if “x” is equal to 2?' ,
a: " if(x 2)",
b: "if(x = 2)",
c: "if(x == 2)",
d: "if(x != 2 )",
ans: "ans3"
}
,
{
question: 'Q20 :for(i=0;i<=array.length;i++), array[i]' ,
a: "return the value of the array",
b: "return the index of the array",
c: "if(x == 2)",
d: "if(x != 2 )",
ans: "ans3"
}
,
{
question: 'Q21 : var i=8; \n if(i>=0){ \n document.write("The number is a positive integer");\n} \n else{\n document.write("The number is a negative integer");\n}' ,
a: "The number is a positive integer.",
b: "length",
c: "The number is a negative integer.",
d: "Compiler error or Run time erorr",
ans: "ans1"
}
,
{
question: 'Q22 : Which of the following will write the message “Hello DataFlair!” in an alert box?' ,
a: " alertBox(“Hello DataFlair!”);",
b: " alert(Hello DataFlair!);",
c: "The number is a negative integer.",
d: " msgAlert(“Hello DataFlair!”);",
ans: "ans1"
}
,
{
question: 'Q23 : If the value of x is 40, then what is the output of the following program? (x % 10 == 0)? console.log(“Divisible by 10”) : console.log(“Not divisible by 10”);' ,
a: "ReferenceError",
b: "Divisible by 10",
c: "Not divisible by 10",
d: "None of the above",
ans: "ans2"
}
,
{
question: 'Q24 : "SMIT" - 3' ,
a: "NaN",
b: " SyntaxError",
c: "T",
d: "None of the above",
ans: "ans1"
}
,
{
question: 'Q25 :4-6+(56)*34',
a: "1902",
b: "1920",
c: "55",
d: "None of the above",
ans: "ans1"
}
]
var question = document.querySelector('#question');
var opt1 = document.querySelector('#op1');
var opt2 = document.querySelector('#op2');
var opt3 = document.querySelector('#op3');
var opt4 = document.querySelector('#op4');
var answers = document.querySelectorAll(".rad-input")
var submit = document.querySelector('#submit');
var scoreboard = document.querySelector('#scoreboard');
var questionCount = 0;
var score = 0;
function questionLoad() {
var questionsList = quizQuestions[questionCount];
question.innerText = questionsList.question;
opt1.innerText = questionsList.a;
opt2.innerText = questionsList.b;
opt3.innerText = questionsList.c;
opt4.innerText = questionsList.d;
}
questionLoad();
function getCheckAnswer() {
var answer;
for (i = 0; i < answers.length; i++) {
if (answers[i].checked) {
answer = answers[i].id
}
}
return answer;
}
function deselect() {
var answer;
for (i = 0; i < answers.length; i++) {
answers[i].checked = false;
}
}
submit.addEventListener("click", () => {
var checkAnswers = getCheckAnswer();
// console.log(checkAnswers)
if (checkAnswers === quizQuestions[questionCount].ans) {
score++
console.log(score)
}
else {
console.log(score)
}
questionCount++;
if (questionCount < quizQuestions.length) {
questionLoad();
deselect();
}
else if (score > 15) {
scoreboard.innerHTML = (
`
<h3>You Scored ${score} / ${quizQuestions.length} </h3>
<p classs="succes">You are Great 🏆</p>
<button class="btn" onclick ="location.reload()";>Play Again</button>
<button class="btn" onclick ="location.href='answer.html'";>check Answers</button>
`
)
scoreboard.classList.remove('score_board');
scoreboard.classList.add('btn');
submit.classList.add('none')
}
else {
scoreboard.innerHTML = (
`
<h3>You Scored ${score} / ${quizQuestions.length} </h3>
<p class="fail">You are fail 😞</p>
<button class="btn" onclick ="location.reload()";>Play Again</button>
<button class="btn" onclick ="location.href='answer.html'";>check Answers</button>
`
)
scoreboard.classList.remove('score_board');
scoreboard.classList.add('btn');
submit.classList.add('none')
}
})
var teacher = "Sir Ghous Ahmed";
if(teacher==="Ghous Ahmed"){
alert("you can enjoy quiz")
}