-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathposttest.js
186 lines (135 loc) · 5.89 KB
/
posttest.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
/////////////////////////////////////////////////////////////////////////////
/////////////////////// Do not modify the below code ////////////////////////
/////////////////////////////////////////////////////////////////////////////
(function() {
function buildQuiz() {
// we'll need a place to store the HTML output
const output = [];
// for each question...
myQuestions.forEach((currentQuestion, questionNumber) => {
// we'll want to store the list of answer choices
const answers = [];
// and for each available answer...
for (letter in currentQuestion.answers) {
// ...add an HTML radio button
answers.push(
`<label>
<input type="radio" name="question${questionNumber}" value="${letter}">
${letter} :
${currentQuestion.answers[letter]}
</label>`
);
}
// add this question and its answers to the output
output.push(
`<div class="question"> ${currentQuestion.question} </div>
<div class="answers"> ${answers.join("")} </div>`
);
});
// finally combine our output list into one string of HTML and put it on the page
quizContainer.innerHTML = output.join("");
}
function showResults() {
// gather answer containers from our quiz
const answerContainers = quizContainer.querySelectorAll(".answers");
// keep track of user's answers
let numCorrect = 0;
// for each question...
myQuestions.forEach((currentQuestion, questionNumber) => {
// find selected answer
const answerContainer = answerContainers[questionNumber];
const selector = `input[name=question${questionNumber}]:checked`;
const userAnswer = (answerContainer.querySelector(selector) || {}).value;
// if answer is correct
if (userAnswer === currentQuestion.correctAnswer) {
// add to the number of correct answers
numCorrect++;
// color the answers green
//answerContainers[questionNumber].style.color = "lightgreen";
} else {
// if answer is wrong or blank
// color the answers red
answerContainers[questionNumber].style.color = "red";
}
});
// show number of correct answers out of total
resultsContainer.innerHTML = `${numCorrect} out of ${myQuestions.length}`;
}
const quizContainer = document.getElementById("quiz");
const resultsContainer = document.getElementById("results");
const submitButton = document.getElementById("submit");
/////////////////////////////////////////////////////////////////////////////
/////////////////////// Do not modify the above code ////////////////////////
/////////////////////////////////////////////////////////////////////////////
/////////////// Write the MCQ below in the exactly same described format ///////////////
const myQuestions = [
{
question: "deQueue() is call only when:-", ///// Write the question inside double quotes
answers: {
a: "new element is deleted.", ///// Write the option 1 inside double quotes
b: "an element is inserted.", ///// Write the option 2 inside double quotes
c: "we check the state of queue", ///// Write the option 3 inside double quotes
d: "None of the options" ///// Write the option 4 inside double quotes
},
correctAnswer: "a" ///// Write the correct option inside double quotes
},
{
question: "Name of the variable that is used for the front side", ///// Write the question inside double quotes
answers: {
a: "REAR", ///// Write the option 1 inside double quotes
b: "END", ///// Write the option 2 inside double quotes
c: "FRONT", ///// Write the option 3 inside double quotes
d: "All of above" ///// Write the option 4 inside double quotes
},
correctAnswer: "c" ///// Write the correct option inside double quotes
}, ///// To add more questions, copy the section below
///// this line
{
question: "IsFull() funtion is used to:-",
answers: {
a: "check that queue is full or not.",
b: "check that queue is empty or not.",
c: "A and B both",
d: "None of these"
},
correctAnswer: "a"
},
{
question: "What is the size range(min, max) of array in simulator?",
answers: {
a: "[5,9]",
b: "(6,9]",
c: "(4,11)",
d: "[5,9)"
},
correctAnswer: "a"
},
/* To add more MCQ's, copy the below section, starting from open curly braces ( { )
till closing curly braces comma ( }, )
and paste it below the curly braces comma ( below correct answer }, ) of above
question
Copy below section
{
question: "This is question n?",
answers: {
a: "Option 1",
b: "Option 2",
c: "Option 3",
d: "Option 4"
},
correctAnswer: "c"
},
Copy above section
*/
];
/////////////////////////////////////////////////////////////////////////////
/////////////////////// Do not modify the below code ////////////////////////
/////////////////////////////////////////////////////////////////////////////
// display quiz right away
buildQuiz();
// on submit, show results
submitButton.addEventListener("click", showResults);
})();
/////////////////////////////////////////////////////////////////////////////
/////////////////////// Do not modify the above code ////////////////////////
/////////////////////////////////////////////////////////////////////////////