-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexam.html
290 lines (272 loc) · 10.5 KB
/
exam.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dynamic Exam Page</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
.correct-answer { background-color: yellow; }
.wrong-answer { background-color: red; }
.selected-answer { background-color: blue; }
</style>
</head>
<body>
<div class="container mt-5">
<h1 class="text-center mb-4">Multiple Choice Exam</h1>
<div id="quiz-container"></div>
</div>
<script>
const quizData = [
{
"question": "What is the largest organelle in a eukaryotic cell?",
"options": ["Nucleus", "Mitochondria", "Lysosome"],
"correct": 0
},
{
"question": "Which macromolecule is involved in catalyzing biological reactions?",
"options": ["Lipids", "Proteins", "Nucleic acids"],
"correct": 1
},
{
"question": "What is the primary function of ribosomes?",
"options": ["Protein synthesis", "Lipid synthesis", "Carbohydrate synthesis"],
"correct": 0
},
{
"question": "What kind of molecules form the basic structure of cell membranes?",
"options": ["Phospholipids", "Proteins", "Carbohydrates"],
"correct": 0
},
{
"question": "What is the smallest cytoskeleton element in a cell?",
"options": ["Microfilament", "Microtubule", "Intermediate filament"],
"correct": 0
},
{
"question": "Which of the following is a function of the Golgi apparatus?",
"options": ["Packaging proteins for export", "Lipid synthesis", "Energy production"],
"correct": 0
},
{
"question": "What is the powerhouse of the cell?",
"options": ["Mitochondria", "Lysosome", "Chloroplast"],
"correct": 0
},
{
"question": "Which phase of the cell cycle involves DNA replication?",
"options": ["S phase", "G1 phase", "G2 phase"],
"correct": 0
},
{
"question": "Which type of bond is the strongest in biological systems?",
"options": ["Covalent bond", "Hydrogen bond", "Ionic bond"],
"correct": 0
},
{
"question": "Which of the following is an example of active transport?",
"options": ["Sodium-potassium pump", "Diffusion", "Osmosis"],
"correct": 0
},
{
"question": "Which part of the cell synthesizes lipids?",
"options": ["Smooth ER", "Rough ER", "Golgi apparatus"],
"correct": 0
},
{
"question": "What is the function of lysosomes?",
"options": ["Break down waste", "Photosynthesis", "Protein synthesis"],
"correct": 0
},
{
"question": "What is the primary component of plant cell walls?",
"options": ["Cellulose", "Chitin", "Peptidoglycan"],
"correct": 0
},
{
"question": "Which organelle is responsible for photosynthesis?",
"options": ["Chloroplast", "Mitochondria", "Nucleus"],
"correct": 0
},
{
"question": "Which molecule is known as the 'energy currency' of the cell?",
"options": ["ATP", "DNA", "RNA"],
"correct": 0
},
{
"question": "Which process allows water to move across the cell membrane?",
"options": ["Osmosis", "Diffusion", "Endocytosis"],
"correct": 0
},
{
"question": "Which of the following has a double membrane?",
"options": ["Mitochondria", "Ribosome", "Peroxisome"],
"correct": 0
},
{
"question": "What is the primary function of the Rough ER?",
"options": ["Protein synthesis", "Lipid synthesis", "Detoxification"],
"correct": 0
},
{
"question": "What are the building blocks of proteins?",
"options": ["Amino acids", "Nucleotides", "Monosaccharides"],
"correct": 0
},
{
"question": "Which molecule forms the backbone of DNA?",
"options": ["Phosphate and sugar", "Protein and lipid", "Carbohydrate and lipid"],
"correct": 0
},
{
"question": "What type of cells contain chloroplasts?",
"options": ["Plant cells", "Animal cells", "Fungal cells"],
"correct": 0
},
{
"question": "Which of the following bonds is crucial for secondary protein structure?",
"options": ["Hydrogen bonds", "Covalent bonds", "Ionic bonds"],
"correct": 0
},
{
"question": "Where does glycolysis take place in the cell?",
"options": ["Cytoplasm", "Mitochondria", "Nucleus"],
"correct": 0
},
{
"question": "What is the role of telomeres in cell division?",
"options": ["Protect chromosome ends", "Encode proteins", "Attach to spindle fibers"],
"correct": 0
},
{
"question": "Which phase follows prophase in mitosis?",
"options": ["Metaphase", "Anaphase", "Telophase"],
"correct": 0
},
{
"question": "Which molecule carries genetic instructions from DNA to the ribosome?",
"options": ["mRNA", "tRNA", "rRNA"],
"correct": 0
},
{
"question": "What is the final electron acceptor in the electron transport chain?",
"options": ["Oxygen", "Water", "Carbon dioxide"],
"correct": 0
},
{
"question": "Which organelle stores genetic information?",
"options": ["Nucleus", "Ribosome", "Endoplasmic reticulum"],
"correct": 0
},
{
"question": "What type of transport involves the movement of large particles into the cell?",
"options": ["Endocytosis", "Exocytosis", "Pinocytosis"],
"correct": 0
},
{
"question": "Which organelle is involved in detoxification of drugs and poisons?",
"options": ["Smooth ER", "Rough ER", "Lysosome"],
"correct": 0
}
];
// Function to build the quiz
function buildQuiz() {
const quizContainer = document.getElementById('quiz-container');
quizData.forEach((q, index) => {
const questionDiv = document.createElement('div');
questionDiv.classList.add('mb-4');
const questionText = document.createElement('h5');
questionText.textContent = `Question ${index + 1}: ${q.question}`;
questionDiv.appendChild(questionText);
q.options.forEach((option, i) => {
const optionButton = document.createElement('button');
optionButton.classList.add('btn', 'btn-outline-primary', 'choice', 'me-2', 'mt-2');
optionButton.textContent = `${String.fromCharCode(65 + i)}. ${option}`;
optionButton.onclick = function () {
checkAnswer(this, i === q.correct);
};
questionDiv.appendChild(optionButton);
});
quizContainer.appendChild(questionDiv);
});
}
// Function to check the answer and set background color
function checkAnswer(button, isCorrect) {
// Reset background color on double click
if (button.classList.contains('selected-answer') || button.classList.contains('correct-answer') || button.classList.contains('wrong-answer')) {
button.classList.remove('selected-answer', 'correct-answer', 'wrong-answer');
button.style.backgroundColor = ''; // Resets to default
return;
}
// Apply colors based on the answer
if (isCorrect) {
button.classList.add('correct-answer');
} else {
button.classList.add('wrong-answer');
const questionDiv = button.parentElement;
const correctBtn = questionDiv.querySelectorAll('button')[quizData[Array.from(questionDiv.parentElement.children).indexOf(questionDiv)].correct];
correctBtn.classList.add('correct-answer');
}
button.classList.add('selected-answer');
}
// Build the quiz on page load
window.onload = buildQuiz;
</script>
</body>
</html>
<!-- if want shuffle quesions -->
<!-- // Function to shuffle an array (Fisher-Yates shuffle algorithm)
function shuffleArray(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
return array;
}
// Function to build the quiz
function buildQuiz() {
const quizContainer = document.getElementById('quiz-container');
// Shuffle the questions
const shuffledQuizData = shuffleArray([...quizData]);
shuffledQuizData.forEach((q, index) => {
const questionDiv = document.createElement('div');
questionDiv.classList.add('mb-4');
const questionText = document.createElement('h5');
questionText.textContent = `Question ${index + 1}: ${q.question}`;
questionDiv.appendChild(questionText);
// Shuffle the options for each question
const shuffledOptions = shuffleArray([...q.options]);
shuffledOptions.forEach((option, i) => {
const optionButton = document.createElement('button');
optionButton.classList.add('btn', 'btn-outline-primary', 'choice', 'me-2', 'mt-2');
optionButton.textContent = `${String.fromCharCode(65 + i)}. ${option}`;
optionButton.onclick = function () {
// Check if the clicked option is the correct one
checkAnswer(this, option === q.options[q.correct]);
};
questionDiv.appendChild(optionButton);
});
quizContainer.appendChild(questionDiv);
});
}
// Function to check the answer and set background color
function checkAnswer(button, isCorrect) {
// Reset background color on double click
if (button.classList.contains('selected-answer') || button.classList.contains('correct-answer') || button.classList.contains('wrong-answer')) {
button.classList.remove('selected-answer', 'correct-answer', 'wrong-answer');
button.style.backgroundColor = ''; // Resets to default
return;
}
// Apply colors based on the answer
if (isCorrect) {
button.classList.add('correct-answer');
} else {
button.classList.add('wrong-answer');
const questionDiv = button.parentElement;
const correctBtn = [...questionDiv.children].find(btn => btn.textContent.includes(q.options[q.correct]));
correctBtn.classList.add('correct-answer');
}
button.classList.add('selected-answer');
}
// Build the quiz on page load
window.onload = buildQuiz; -->