-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmonika.html
More file actions
394 lines (352 loc) · 21.2 KB
/
monika.html
File metadata and controls
394 lines (352 loc) · 21.2 KB
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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Interactive Vocabulary Test</title>
<script src="https://cdn.tailwindcss.com"></script>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
<style>
body {
font-family: 'Inter', sans-serif;
}
/* Custom styles for matching game selections */
.word-selected {
background-color: #93c5fd; /* bg-blue-300 */
border-color: #60a5fa; /* border-blue-400 */
box-shadow: 0 0 0 2px #3b82f6; /* ring-2 ring-blue-500 */
}
.def-selected {
background-color: #a7f3d0; /* bg-green-300 */
border-color: #4ade80; /* border-green-400 */
box-shadow: 0 0 0 2px #22c55e; /* ring-2 ring-green-500 */
}
.paired {
background-color: #d1d5db; /* bg-gray-300 */
color: #6b7280; /* text-gray-500 */
cursor: not-allowed;
}
</style>
</head>
<!-- Changed background color from bg-gray-50 to bg-green-100 for a new theme. -->
<body class="bg-green-50 flex items-center justify-center min-h-screen p-4">
<!-- The main container for the quiz app. Rounded corners and a shadow give it a card-like appearance. -->
<!-- overflow-hidden is added to ensure the image corners are clipped by the parent's rounded border. -->
<main id="app-container" class="bg-white rounded-xl shadow-2xl max-w-4xl w-full overflow-hidden">
<!-- Header Image: w-full makes it span the full width of the container. -->
<!-- The 'max-w-xs' and 'mx-auto' classes were removed to allow the image to fill the container. -->
<img
src="https://static.wixstatic.com/media/0f55f2_d0ce1f16f68b4f57ab1ee7c6337b7902~mv2.jpg"
alt="An illustration of books, a lightbulb, and gears, symbolizing learning and knowledge"
class="w-full"
onerror="this.onerror=null;this.src='https://placehold.co/600x250/e2e8f0/64748b?text=Vocabulary+Test';"
>
<!-- This div wraps the actual quiz content and provides padding. -->
<div class="p-6 md:p-8">
<!-- Intro Screen -->
<div id="intro-view" class="text-center">
<h1 class="text-4xl font-bold mb-4 text-gray-800">End of Year Vocabulary Test</h1>
<p class="text-lg text-gray-600 mb-8">This test uses 40 words and includes multiple choice, fill-in-the-blank, and matching questions.</p>
<button id="start-btn" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-3 px-6 rounded-lg shadow-lg transition duration-300 ease-in-out transform hover:scale-105">
Start Test
</button>
</div>
<!-- Test Screen -->
<div id="test-view" class="hidden">
<!-- Test content will be generated here by JavaScript -->
</div>
<!-- Results Screen -->
<div id="results-view" class="hidden">
<!-- Results content will be generated here by JavaScript -->
</div>
</div>
</main>
<script>
// --- DOM Elements ---
const introView = document.getElementById('intro-view');
const testView = document.getElementById('test-view');
const resultsView = document.getElementById('results-view');
const startBtn = document.getElementById('start-btn');
// --- STATE ---
let questions = [];
let currentQuestionIndex = 0;
let userAnswers = {};
let score = 0;
let startTime = null;
let endTime = null;
let selectedWord = null;
let selectedDef = null;
// --- VOCABULARY DATA ---
const vocabularyList = [
{ word: 'Run out of steam', definition: 'To lose impetus or enthusiasm.' },
{ word: 'Resolution', definition: 'A firm decision to do or not to do something.' },
{ word: 'Permission', definition: 'The action of officially allowing someone to do a particular thing.' },
{ word: 'Adopt', definition: 'To choose to take up, follow, or use.' },
{ word: 'Buy-in', definition: 'Agreement on a course of action.' },
{ word: 'Constructive criticism', definition: 'Offering valid opinions about others\' work in a friendly manner.' },
{ word: 'Landfill', definition: 'A place where waste is buried in the ground.' },
{ word: 'Gadget', definition: 'A small, ingenious mechanical or electronic device.' },
{ word: 'Inevitably', definition: 'As is certain to happen; unavoidably.' },
{ word: 'Persistence', definition: 'Continuing a course of action despite difficulty.' },
{ word: 'Obliged', definition: 'To be legally or morally bound to do something.' },
{ word: 'Anxiety', definition: 'A feeling of worry, nervousness, or unease.' },
{ word: 'Improvise', definition: 'To create and perform spontaneously or without preparation.' },
{ word: 'Obsolete', definition: 'No longer produced or used; out of date.' },
{ word: 'Automated', definition: 'Operated by largely automatic equipment.' },
{ word: 'Promoted', definition: 'To raise someone to a higher position or rank.' },
{ word: 'Conspiracy theory', definition: 'A belief that a covert organization is responsible for an event.' },
{ word: 'Cramped', definition: 'Feeling uncomfortably confined by lack of space.' },
{ word: 'Hoard', definition: 'To accumulate and hide or store away valued objects.' },
{ word: 'Addictive', definition: 'Causing or likely to cause dependency.' },
{ word: 'Allies', definition: 'People or groups that cooperate for a common purpose.' },
{ word: 'Digitize', definition: 'To convert pictures, text, or sound into a digital form.' },
{ word: 'Wrestle', definition: 'To struggle with a difficulty or problem.' },
{ word: 'Stride', definition: 'To walk with long, decisive steps.' },
{ word: 'Shuffle', definition: 'To walk by dragging one\'s feet along the ground.' },
{ word: 'Wander', definition: 'To walk or move in a leisurely or aimless way.' },
{ word: 'Heave', definition: 'To lift or haul something heavy with great effort.' },
{ word: 'Leap', definition: 'To jump or spring a long way.' },
{ word: 'Rebound relationship', definition: 'A romantic relationship started shortly after a breakup.' },
{ word: 'Appreciated', definition: 'To be recognized for one\'s full worth.' },
{ word: 'Acknowledged', definition: 'To be accepted or have the truth of admitted.' },
{ word: 'Substitute', definition: 'To act or serve in place of another.' },
{ word: 'Novice', definition: 'A person new to and inexperienced in a situation.' },
{ word: 'Efficiency', definition: 'The quality of working in a well-organized and competent way.' },
{ word: 'Outright lie', definition: 'A completely and openly false statement.' },
{ word: 'Demolish', definition: 'To pull or knock down a building.' },
{ word: 'Fatality', definition: 'A death resulting from an accident or disaster.' },
{ word: 'Intermittent', definition: 'Occurring at irregular intervals; not continuous.' },
{ word: 'Forbid', definition: 'To refuse to allow something.' },
{ word: 'Congestion', definition: 'The state of being blocked or overly full.' }
];
// --- FUNCTIONS ---
const shuffleArray = (array) => [...array].sort(() => Math.random() - 0.5);
const generateTestQuestions = () => {
const shuffledVocab = shuffleArray(vocabularyList);
const mcq = shuffledVocab.slice(0, 10).map(vocab => {
const incorrectDefs = vocabularyList.filter(v => v.word !== vocab.word).map(v => v.definition);
const options = shuffleArray([vocab.definition, ...shuffleArray(incorrectDefs).slice(0, 3)]);
return {
type: 'multiple-choice',
question: `What is the definition of "${vocab.word}"?`,
word: vocab.word,
options: options,
correctAnswer: vocab.definition
};
});
const fillInBlanksData = [
{ question: 'It is very difficult to get ________ when the new software is more complicated.', word: 'Buy-in' },
{ question: 'Admin jobs are becoming ________ because of AI.', word: 'Obsolete' },
{ question: 'The room is now very ________ with the new wardrobe.', word: 'Cramped' },
{ question: 'Running can be very ________ if you do it every day.', word: 'Addictive' },
{ question: 'Soldiers ________ with confidence, showing their training.', word: 'Stride' },
{ question: 'She had to ________ with the difficult decision for weeks.', word: 'Wrestle' },
{ question: 'As a ________ in coding, he often asked for help.', word: 'Novice' },
{ question: 'The train service is ________, so you can never be sure when it will arrive.', word: 'Intermittent' },
{ question: 'The old factory is scheduled for the city to ________ it next year.', word: 'Demolish' },
{ question: 'My parents ________ me from going out on school nights.', word: 'Forbid' }
];
const fillInBlanks = shuffleArray(fillInBlanksData).slice(0, 8).map(q => ({ ...q, type: 'fill-in-the-blank', correctAnswer: q.word }));
const matchingWords = shuffledVocab.slice(10, 18);
const matchingDefs = shuffleArray(matchingWords.map(v => v.definition));
const matchingQuestion = {
type: 'matching',
question: 'Match the words to their correct definitions.',
words: matchingWords.map(v => v.word),
definitions: matchingDefs,
correctPairs: matchingWords.reduce((acc, v) => ({ ...acc, [v.word]: v.definition }), {})
};
questions = shuffleArray([...mcq, ...fillInBlanks, matchingQuestion]);
};
const switchView = (view) => {
introView.classList.add('hidden');
testView.classList.add('hidden');
resultsView.classList.add('hidden');
document.getElementById(`${view}-view`).classList.remove('hidden');
}
const startTest = () => {
generateTestQuestions();
currentQuestionIndex = 0;
userAnswers = {};
score = 0;
startTime = Date.now();
endTime = null;
renderQuestion();
switchView('test');
};
const renderQuestion = () => {
const q = questions[currentQuestionIndex];
if (!q) return;
const progress = ((currentQuestionIndex + 1) / questions.length) * 100;
let content = `
<div class="w-full bg-gray-200 rounded-full h-2.5 mb-4">
<div class="bg-blue-500 h-2.5 rounded-full" style="width: ${progress}%"></div>
</div>
<div class="mb-4 text-gray-700">
<p class="text-xl font-semibold">Question ${currentQuestionIndex + 1} of ${questions.length}</p>
<p class="text-lg mt-2">${q.question}</p>
</div>
`;
if (q.type === 'multiple-choice') {
content += `<div class="grid grid-cols-1 md:grid-cols-2 gap-4">`;
q.options.forEach(option => {
content += `<button class="mc-option p-4 rounded-lg border-2 transition-all duration-200 text-left bg-white border-gray-300 hover:border-blue-400" data-answer="${option}">${option}</button>`;
});
content += `</div>`;
}
if (q.type === 'fill-in-the-blank') {
content += `<input type="text" id="fill-in-blank-input" class="mt-2 p-3 border rounded-lg w-full focus:outline-none focus:ring-2 focus:ring-blue-500" placeholder="Type the correct word...">`;
}
if (q.type === 'matching') {
content += `<div class="flex flex-col md:flex-row justify-between gap-8 mt-4">`;
content += `<div class="flex-1 flex flex-col gap-2"><h4 class="font-semibold text-center text-gray-600">Words</h4>`;
q.words.forEach(word => {
content += `<button class="match-word p-3 rounded-lg border-2 transition-all duration-200 bg-white hover:bg-blue-100" data-word="${word}">${word}</button>`;
});
content += `</div>`;
content += `<div class="flex-1 flex flex-col gap-2"><h4 class="font-semibold text-center text-gray-600">Definitions</h4>`;
q.definitions.forEach(def => {
content += `<button class="match-def p-3 rounded-lg border-2 transition-all duration-200 text-left bg-white hover:bg-green-100" data-def="${def}">${def}</button>`;
});
content += `</div></div>`;
}
content += `
<div class="mt-8 flex justify-end">
<button id="next-btn" class="bg-green-500 hover:bg-green-700 text-white font-bold py-2 px-6 rounded-lg shadow-md transition duration-300">
${currentQuestionIndex < questions.length - 1 ? 'Next' : 'Finish'}
</button>
</div>`;
testView.innerHTML = content;
addQuestionEventListeners();
};
const addQuestionEventListeners = () => {
document.getElementById('next-btn').addEventListener('click', nextQuestion);
const q = questions[currentQuestionIndex];
if (q.type === 'multiple-choice') {
document.querySelectorAll('.mc-option').forEach(btn => {
btn.addEventListener('click', (e) => {
document.querySelectorAll('.mc-option').forEach(b => b.classList.remove('bg-blue-500', 'border-blue-500', 'text-white', 'shadow-md'));
e.target.classList.add('bg-blue-500', 'border-blue-500', 'text-white', 'shadow-md');
userAnswers[q.word] = e.target.dataset.answer;
});
});
}
if (q.type === 'fill-in-the-blank') {
document.getElementById('fill-in-blank-input').addEventListener('input', (e) => {
userAnswers[q.word] = e.target.value;
});
}
if (q.type === 'matching') {
document.querySelectorAll('.match-word').forEach(btn => btn.addEventListener('click', handleMatchClick));
document.querySelectorAll('.match-def').forEach(btn => btn.addEventListener('click', handleMatchClick));
}
};
const handleMatchClick = (e) => {
const btn = e.target;
const key = currentQuestionIndex;
if (btn.classList.contains('match-word')) {
if(selectedWord) selectedWord.classList.remove('word-selected');
selectedWord = btn;
btn.classList.add('word-selected');
} else if (btn.classList.contains('match-def')) {
if(selectedDef) selectedDef.classList.remove('def-selected');
selectedDef = btn;
btn.classList.add('def-selected');
}
if (selectedWord && selectedDef) {
if (!userAnswers[key]) userAnswers[key] = {};
userAnswers[key][selectedWord.dataset.word] = selectedDef.dataset.def;
selectedWord.classList.add('paired');
selectedDef.classList.add('paired');
selectedWord.classList.remove('word-selected');
selectedDef.classList.remove('def-selected');
selectedWord = null;
selectedDef = null;
}
};
const nextQuestion = () => {
if (currentQuestionIndex < questions.length - 1) {
currentQuestionIndex++;
renderQuestion();
} else {
finishTest();
}
};
const finishTest = () => {
endTime = Date.now();
score = 0;
questions.forEach((q, index) => {
const key = q.type === 'matching' ? index : q.word;
const userAnswer = userAnswers[key];
if (!userAnswer) return;
if (q.type === 'multiple-choice' && userAnswer === q.correctAnswer) {
score++;
} else if (q.type === 'fill-in-the-blank' && userAnswer.trim().toLowerCase() === q.correctAnswer.toLowerCase()) {
score++;
} else if (q.type === 'matching') {
let correctMatches = 0;
Object.keys(userAnswer).forEach(word => {
if (q.correctPairs[word] === userAnswer[word]) {
correctMatches++;
}
});
score += (correctMatches / q.words.length);
}
});
renderResults();
switchView('results');
};
const renderResults = () => {
const timeTaken = ((endTime - startTime) / 1000).toFixed(2);
const percentage = questions.length > 0 ? ((score / questions.length) * 100).toFixed(0) : 0;
let content = `
<div class="text-center">
<h2 class="text-3xl font-bold mb-4 text-gray-800">Test Complete!</h2>
<div class="bg-gray-100 p-6 rounded-lg shadow-inner mb-6">
<p class="text-2xl text-gray-700">Your Score: <span class="font-bold text-blue-600">${score.toFixed(1)} / ${questions.length}</span></p>
<p class="text-4xl font-bold text-blue-600 mt-2">${percentage}%</p>
<p class="text-md text-gray-600 mt-4">Time Taken: ${timeTaken} seconds</p>
</div>
<div class="text-left mt-8 max-h-96 overflow-y-auto pr-2">
<h3 class="text-2xl font-semibold mb-4 border-b pb-2">Review Your Answers</h3>
`;
questions.forEach((q, index) => {
const key = q.type === 'matching' ? index : q.word;
const userAnswer = userAnswers[key];
if (q.type === 'matching') {
content += `<div class="mb-4 p-4 rounded-lg bg-white shadow"><p class="font-semibold">${index + 1}. ${q.question}</p><ul class="list-disc list-inside mt-2">`;
q.words.forEach(word => {
const userDef = userAnswer ? userAnswer[word] : "No answer";
const correctDef = q.correctPairs[word];
const isMatchCorrect = userDef === correctDef;
content += `<li class="${isMatchCorrect ? 'text-green-700' : 'text-red-700'}"><strong>${word}:</strong> Your match "${userDef || 'none'}" was ${isMatchCorrect ? 'correct' : `incorrect. Correct was "${correctDef}"`}.</li>`;
});
content += `</ul></div>`;
} else {
let isCorrect = false;
let correctAnswerText = '';
if (q.type === 'multiple-choice') {
isCorrect = userAnswer === q.correctAnswer;
correctAnswerText = q.correctAnswer;
} else if (q.type === 'fill-in-the-blank') {
isCorrect = userAnswer && userAnswer.trim().toLowerCase() === q.correctAnswer.toLowerCase();
correctAnswerText = q.correctAnswer;
}
content += `<div class="mb-4 p-4 rounded-lg shadow ${isCorrect ? 'bg-green-100 border-l-4 border-green-500' : 'bg-red-100 border-l-4 border-red-500'}">
<p class="font-semibold">${index + 1}. ${q.question}</p>
<p class="mt-2">Your answer: <span class="font-medium">${userAnswer || 'No answer'}</span></p>
${!isCorrect ? `<p class="mt-1">Correct answer: <span class="font-medium">${correctAnswerText}</span></p>` : ''}
</div>`;
}
});
content += `</div><button id="try-again-btn" class="mt-8 bg-blue-500 hover:bg-blue-700 text-white font-bold py-3 px-6 rounded-lg shadow-lg transition duration-300 transform hover:scale-105">Try Again</button></div>`;
resultsView.innerHTML = content;
document.getElementById('try-again-btn').addEventListener('click', () => {
switchView('intro');
});
};
// --- Initial Event Listener ---
startBtn.addEventListener('click', startTest);
</script>
</body>
</html>