-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdana.html
More file actions
391 lines (349 loc) · 21.5 KB
/
dana.html
File metadata and controls
391 lines (349 loc) · 21.5 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
<!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>
<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. -->
<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. -->
<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 vocabulary from Dana's list 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 (From dana vocab.txt) ---
const vocabularyList = [
{ word: 'Off season', definition: 'A time of year when there is less activity in a particular industry or sport.' },
{ word: 'Peak season', definition: 'The time of year when a place has the most visitors and prices are highest.' },
{ word: 'Day to day', definition: 'Happening regularly every day.' },
{ word: 'Ate out', definition: 'To have a meal in a restaurant, rather than at home.' },
{ word: 'Commute', definition: 'To travel some distance between one\'s home and place of work on a regular basis.' },
{ word: 'Resolution', definition: 'A firm decision to do or not to do something.' },
{ word: 'Avoid', definition: 'To keep away from or stop oneself from doing (something).' },
{ word: 'Sledging', definition: 'Riding on a sled, typically down a hill.' },
{ word: 'Injure', definition: 'To harm or damage someone or something.' },
{ word: 'Soaked', definition: 'Extremely wet.' },
{ word: 'Obsolete', definition: 'No longer produced or used; out of date.' },
{ word: 'Competitors', definition: 'People or organizations that are competing against each other.' },
{ word: 'Word of mouth', definition: 'The passing of information from person to person by oral communication.' },
{ word: 'Drought', definition: 'A prolonged period of abnormally low rainfall, leading to a shortage of water.' },
{ word: 'Steeper', definition: 'Rising or falling sharply.' },
{ word: 'Contagious', definition: 'Spreadable from one person or organism to another by direct or indirect contact.' },
{ word: 'Boom', definition: 'A period of great prosperity or rapid economic growth.' },
{ word: 'Hike prices', definition: 'To increase prices by a large amount.' },
{ word: 'Make a profit', definition: 'To earn or gain money from a business or investment.' },
{ word: 'Fragile', definition: 'Easily broken or damaged.' },
{ word: 'Upgrade', definition: 'To raise (something) to a higher standard, in particular improve (equipment or machinery) by adding or replacing components.' },
{ word: 'Objective', definition: 'Not influenced by personal feelings or opinions in considering and representing facts.' },
{ word: 'Subjective', definition: 'Based on or influenced by personal feelings, tastes, or opinions.'},
{ word: 'False economy', definition: 'An apparent financial saving that in fact leads to greater expenditure.' },
{ word: 'Shelf life', definition: 'The length of time for which an item remains usable, fit for consumption, or saleable.' },
{ word: 'Adaptable', definition: 'Able to adjust to new conditions.' },
{ word: 'Weeds', definition: 'Wild plants growing where they are not wanted.' },
{ word: 'Hatch', definition: 'To emerge from an egg.' },
{ word: 'Coverage', definition: 'The area in which a service, like an internet signal, is available.' },
{ word: 'Acquaintances', definition: 'People one knows slightly, but who are not close friends.' },
{ word: 'Bait', definition: 'Food used to entice fish or other animals as prey.' },
{ word: 'Breakage', definition: 'The action of breaking something, or the state of being broken.' },
{ word: 'Scrap', definition: 'Discarded metal for reprocessing.' },
{ word: 'Overspent', definition: 'To spend more than the intended amount.' },
{ word: 'Regret', definition: 'To feel sad, repentant, or disappointed over (something that has happened or been done).' },
{ word: 'Put up with', definition: 'To tolerate or endure something.' },
{ word: 'Otherworldly', definition: 'Relating to an imaginary or spiritual world.' },
{ word: 'Duty free', definition: 'Exempt from payment of customs or excise duty.' },
{ word: 'Efficiency', definition: 'The quality of working in a well-organized and competent way.' },
{ word: 'Volunteers', definition: 'People who freely offer to take part in an enterprise or undertake a task.' }
];
// --- FUNCTIONS ---
const shuffleArray = (array) => [...array].sort(() => Math.random() - 0.5);
const generateTestQuestions = () => {
const shuffledVocab = shuffleArray(vocabularyList);
const mcq = shuffledVocab.slice(0, 15).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: 'If you travel during the ________, hotels are much more expensive.', word: 'Peak season' },
{ question: 'By the time I walked to the bus stop in the storm, I was completely ________.', word: 'Soaked' },
{ question: 'Old technology quickly becomes ________ when new versions are released.', word: 'Obsolete' },
{ question: 'The best advertising is ________, when customers recommend you.', word: 'Word of mouth' },
{ question: 'After a long period with no rain, the country experienced a severe ________.', word: 'Drought' },
{ question: 'The illness is highly ________, so you should stay home to avoid spreading it.', word: 'Contagious' },
{ question: 'The ice on the lake is too ________ to skate on safely.', word: 'Fragile' },
{ question: 'Buying the cheapest option can be a ________ if it breaks and you have to buy another.', word: 'False economy' },
{ question: 'I only know him casually; we are just ________.', word: 'Acquaintances' },
{ question: 'I really ________ not starting the project sooner, as now I am behind schedule.', word: 'Regret' }
];
const fillInBlanks = shuffleArray(fillInBlanksData).slice(0, 8).map(q => ({ ...q, type: 'fill-in-the-blank', correctAnswer: q.word }));
const matchingWords = shuffledVocab.slice(15, 25);
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 || q.correctAnswer);
const userAnswer = userAnswers[key];
if (userAnswer === undefined) 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 || q.correctAnswer);
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>