LAshi commited on
Commit
1847f37
·
verified ·
1 Parent(s): 971c299

remove heading - Initial Deployment

Browse files
Files changed (2) hide show
  1. README.md +6 -4
  2. index.html +583 -19
README.md CHANGED
@@ -1,10 +1,12 @@
1
  ---
2
- title: Calculation
3
- emoji: 🏃
4
  colorFrom: red
5
- colorTo: pink
6
  sdk: static
7
  pinned: false
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: calculation
3
+ emoji: 🐳
4
  colorFrom: red
5
+ colorTo: gray
6
  sdk: static
7
  pinned: false
8
+ tags:
9
+ - deepsite
10
  ---
11
 
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
index.html CHANGED
@@ -1,19 +1,583 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Ultimate Speed Math Trainer</title>
7
+ <script src="https://cdn.tailwindcss.com"></script>
8
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
9
+ <style>
10
+ .timer-bar {
11
+ transition: width linear;
12
+ height: 4px;
13
+ }
14
+
15
+ .feedback-message {
16
+ opacity: 0;
17
+ transition: opacity 0.3s ease;
18
+ height: 24px;
19
+ }
20
+
21
+ .feedback-message.show {
22
+ opacity: 1;
23
+ }
24
+
25
+ .settings-panel {
26
+ transform: translateX(-100%);
27
+ transition: transform 0.3s ease;
28
+ }
29
+
30
+ .settings-panel.open {
31
+ transform: translateX(0);
32
+ }
33
+
34
+ @media (max-width: 640px) {
35
+ .settings-panel {
36
+ width: 100%;
37
+ }
38
+ }
39
+ </style>
40
+ </head>
41
+ <body class="bg-gray-900 text-gray-100 min-h-screen flex flex-col">
42
+ <div class="container mx-auto px-4 py-8 pb-16 sm:pb-8 flex-1 flex flex-col">
43
+ <!-- Header with stats -->
44
+ <header class="flex justify-between items-center mb-8">
45
+ <button id="settings-btn" class="text-gray-400 hover:text-white p-2">
46
+ <i class="fas fa-cog text-2xl transition-opacity duration-300"></i>
47
+ </button>
48
+ <div class="flex space-x-4 text-sm">
49
+ <div class="bg-gray-800 px-3 py-1 rounded">
50
+ <span class="text-green-400">✓</span> <span id="correct-count">0</span>
51
+ </div>
52
+ <div class="bg-gray-800 px-3 py-1 rounded">
53
+ <span class="text-red-400">✗</span> <span id="incorrect-count">0</span>
54
+ </div>
55
+ <div class="bg-gray-800 px-3 py-1 rounded">
56
+ <span class="text-yellow-400">%</span> <span id="accuracy">0</span>
57
+ </div>
58
+ </div>
59
+ </header>
60
+
61
+ <!-- Main training area -->
62
+ <main class="flex-1 flex flex-col items-center justify-center">
63
+ <!-- Timer bar -->
64
+ <div class="w-full bg-gray-700 rounded-full mb-6">
65
+ <div id="timer-bar" class="timer-bar bg-blue-500 rounded-full" style="width: 100%"></div>
66
+ </div>
67
+
68
+ <!-- Question display -->
69
+ <div id="question" class="text-5xl sm:text-6xl md:text-8xl font-bold mb-8 sm:mb-12 text-center min-h-[80px] sm:min-h-[120px] flex items-center justify-center">
70
+ Ready?
71
+ </div>
72
+
73
+ <!-- Answer input -->
74
+ <div class="w-full max-w-md mb-6 sm:mb-8 px-2 sm:px-0">
75
+ <input
76
+ type="number"
77
+ id="answer-input"
78
+ class="w-full bg-gray-800 text-2xl sm:text-3xl text-center py-3 sm:py-4 px-4 sm:px-6 rounded-lg border-2 border-gray-700 focus:border-blue-500 focus:outline-none"
79
+ placeholder="Your answer"
80
+ autofocus
81
+ >
82
+ </div>
83
+
84
+ <!-- Feedback message -->
85
+ <div id="feedback" class="feedback-message text-xl font-semibold mb-4"></div>
86
+
87
+ </main>
88
+ </div>
89
+
90
+ <!-- Settings backdrop (hidden by default) -->
91
+ <div id="settings-backdrop" class="fixed inset-0 bg-black bg-opacity-50 z-0 opacity-0 pointer-events-none transition-opacity duration-300"></div>
92
+
93
+ <!-- Settings panel (hidden by default) -->
94
+ <div id="settings-panel" class="settings-panel fixed inset-y-0 left-0 w-full sm:w-96 bg-gray-800 shadow-xl p-4 sm:p-6 overflow-y-auto z-10 border-r border-gray-700">
95
+ <div class="flex justify-between items-center mb-6">
96
+ <h2 class="text-2xl font-bold text-blue-400">Configuration</h2>
97
+ <button id="close-settings" class="text-gray-400 hover:text-white">
98
+ <i class="fas fa-times text-2xl"></i>
99
+ </button>
100
+ </div>
101
+
102
+ <!-- Mode selection -->
103
+ <div class="mb-8 pb-6 border-b border-gray-700">
104
+ <h3 class="text-lg font-semibold mb-3">Mode</h3>
105
+ <div class="space-y-2">
106
+ <label class="flex items-center space-x-3">
107
+ <input type="radio" name="mode" value="multiplication" class="form-radio text-blue-500" checked>
108
+ <span>Multiplication (A × B = ?)</span>
109
+ </label>
110
+ <label class="flex items-center space-x-3">
111
+ <input type="radio" name="mode" value="factoring" class="form-radio text-blue-500">
112
+ <span>Factoring (C ÷ A = ?)</span>
113
+ </label>
114
+ </div>
115
+ </div>
116
+
117
+ <!-- Number ranges -->
118
+ <div class="mb-8 pb-6 border-b border-gray-700">
119
+ <h3 class="text-lg font-semibold mb-3">Number Ranges</h3>
120
+
121
+ <div class="grid grid-cols-2 gap-4 mb-4">
122
+ <div>
123
+ <label class="block text-sm font-medium mb-1">Multiplier Min (A)</label>
124
+ <input type="number" id="multiplier-min" class="w-full bg-gray-700 border border-gray-600 rounded px-3 py-2 focus:border-blue-500 focus:outline-none" value="2" min="1">
125
+ </div>
126
+ <div>
127
+ <label class="block text-sm font-medium mb-1">Multiplier Max (A)</label>
128
+ <input type="number" id="multiplier-max" class="w-full bg-gray-700 border border-gray-600 rounded px-3 py-2" value="12" min="1">
129
+ </div>
130
+ </div>
131
+
132
+ <div class="grid grid-cols-2 gap-4 mb-4">
133
+ <div>
134
+ <label class="block text-sm font-medium mb-1">Multiplicand Min (B)</label>
135
+ <input type="number" id="multiplicand-min" class="w-full bg-gray-700 border border-gray-600 rounded px-3 py-2" value="2" min="1">
136
+ </div>
137
+ <div>
138
+ <label class="block text-sm font-medium mb-1">Multiplicand Max (B)</label>
139
+ <input type="number" id="multiplicand-max" class="w-full bg-gray-700 border border-gray-600 rounded px-3 py-2" value="12" min="1">
140
+ </div>
141
+ </div>
142
+
143
+ <div id="product-range-container" class="grid grid-cols-2 gap-4 hidden">
144
+ <div>
145
+ <label class="block text-sm font-medium mb-1">Product Min (C)</label>
146
+ <input type="number" id="product-min" class="w-full bg-gray-700 border border-gray-600 rounded px-3 py-2" value="10" min="1">
147
+ </div>
148
+ <div>
149
+ <label class="block text-sm font-medium mb-1">Product Max (C)</label>
150
+ <input type="number" id="product-max" class="w-full bg-gray-700 border border-gray-600 rounded px-3 py-2" value="100" min="1">
151
+ </div>
152
+ </div>
153
+ </div>
154
+
155
+ <!-- Exclusions -->
156
+ <div class="mb-8 pb-6 border-b border-gray-700">
157
+ <h3 class="text-lg font-semibold mb-3">Exclusions</h3>
158
+ <div>
159
+ <label class="block text-sm font-medium mb-1">Exclude these numbers (comma separated)</label>
160
+ <input type="text" id="exclude-list" class="w-full bg-gray-700 border border-gray-600 rounded px-3 py-2" placeholder="e.g., 5, 10, 11">
161
+ <p class="text-xs text-gray-400 mt-1">Numbers to exclude from appearing in problems</p>
162
+ </div>
163
+ </div>
164
+
165
+ <!-- Time limit -->
166
+ <div class="mb-8">
167
+ <h3 class="text-lg font-semibold mb-3">Time Limit (seconds)</h3>
168
+ <input type="number" id="time-limit" class="w-full bg-gray-700 border border-gray-600 rounded px-3 py-2" value="5" min="1">
169
+ </div>
170
+
171
+ <!-- Action buttons -->
172
+ <div class="flex space-x-3">
173
+ <button id="save-settings" class="flex-1 bg-blue-600 hover:bg-blue-700 text-white font-medium py-3 px-4 rounded">
174
+ Save & Restart
175
+ </button>
176
+ <button id="reset-stats" class="bg-gray-700 hover:bg-gray-600 text-white font-medium py-3 px-4 rounded">
177
+ Reset Stats
178
+ </button>
179
+ </div>
180
+ </div>
181
+
182
+ <script>
183
+ // Configuration object with default values
184
+ let config = {
185
+ mode: 'multiplication',
186
+ multiplierMin: 2,
187
+ multiplierMax: 12,
188
+ multiplicandMin: 2,
189
+ multiplicandMax: 12,
190
+ productMin: 10,
191
+ productMax: 100,
192
+ excludeList: [],
193
+ timeLimit: 5
194
+ };
195
+
196
+ // Game state
197
+ let state = {
198
+ currentQuestion: null,
199
+ correctAnswer: null,
200
+ timer: null,
201
+ timeLeft: 0,
202
+ correctCount: 0,
203
+ incorrectCount: 0,
204
+ isRunning: false
205
+ };
206
+
207
+ // DOM elements
208
+ const elements = {
209
+ question: document.getElementById('question'),
210
+ answerInput: document.getElementById('answer-input'),
211
+ feedback: document.getElementById('feedback'),
212
+ timerBar: document.getElementById('timer-bar'),
213
+ correctCount: document.getElementById('correct-count'),
214
+ incorrectCount: document.getElementById('incorrect-count'),
215
+ accuracy: document.getElementById('accuracy'),
216
+ settingsBtn: document.getElementById('settings-btn'),
217
+ settingsPanel: document.getElementById('settings-panel'),
218
+ closeSettings: document.getElementById('close-settings'),
219
+ saveSettings: document.getElementById('save-settings'),
220
+ resetStats: document.getElementById('reset-stats'),
221
+ modeRadios: document.querySelectorAll('input[name="mode"]'),
222
+ multiplierMin: document.getElementById('multiplier-min'),
223
+ multiplierMax: document.getElementById('multiplier-max'),
224
+ multiplicandMin: document.getElementById('multiplicand-min'),
225
+ multiplicandMax: document.getElementById('multiplicand-max'),
226
+ productMin: document.getElementById('product-min'),
227
+ productMax: document.getElementById('product-max'),
228
+ productRangeContainer: document.getElementById('product-range-container'),
229
+ excludeList: document.getElementById('exclude-list'),
230
+ timeLimit: document.getElementById('time-limit')
231
+ };
232
+
233
+ // Initialize the game
234
+ function init() {
235
+ loadConfig();
236
+ updateStats();
237
+ setupEventListeners();
238
+ updateModeUI();
239
+ generateQuestion();
240
+ }
241
+
242
+ // Load config from localStorage
243
+ function loadConfig() {
244
+ const savedConfig = localStorage.getItem('mathTrainerConfig');
245
+ if (savedConfig) {
246
+ Object.assign(config, JSON.parse(savedConfig));
247
+ updateSettingsForm();
248
+ }
249
+ }
250
+
251
+ // Save config to localStorage
252
+ function saveConfig() {
253
+ localStorage.setItem('mathTrainerConfig', JSON.stringify(config));
254
+ }
255
+
256
+ // Update the settings form with current config values
257
+ function updateSettingsForm() {
258
+ // Set radio button
259
+ document.querySelector(`input[name="mode"][value="${config.mode}"]`).checked = true;
260
+
261
+ // Set number inputs
262
+ elements.multiplierMin.value = config.multiplierMin;
263
+ elements.multiplierMax.value = config.multiplierMax;
264
+ elements.multiplicandMin.value = config.multiplicandMin;
265
+ elements.multiplicandMax.value = config.multiplicandMax;
266
+ elements.productMin.value = config.productMin;
267
+ elements.productMax.value = config.productMax;
268
+ elements.excludeList.value = config.excludeList.join(', ');
269
+ elements.timeLimit.value = config.timeLimit;
270
+
271
+ updateModeUI();
272
+ }
273
+
274
+ // Update UI based on selected mode
275
+ function updateModeUI() {
276
+ if (config.mode === 'factoring') {
277
+ elements.productRangeContainer.classList.remove('hidden');
278
+ } else {
279
+ elements.productRangeContainer.classList.add('hidden');
280
+ }
281
+ }
282
+
283
+ // Set up event listeners
284
+ function setupEventListeners() {
285
+ // Answer submission
286
+ elements.answerInput.addEventListener('keydown', (e) => {
287
+ if (e.key === 'Enter') {
288
+ checkAnswer();
289
+ }
290
+ });
291
+
292
+ // Settings button
293
+ elements.settingsBtn.addEventListener('click', () => {
294
+ elements.settingsPanel.classList.add('open');
295
+ document.getElementById('settings-backdrop').classList.add('opacity-100', 'pointer-events-auto');
296
+ elements.settingsBtn.querySelector('i').classList.add('opacity-0');
297
+ elements.answerInput.blur();
298
+ });
299
+
300
+ // Close settings
301
+ elements.closeSettings.addEventListener('click', () => {
302
+ elements.settingsPanel.classList.remove('open');
303
+ document.getElementById('settings-backdrop').classList.remove('opacity-100', 'pointer-events-auto');
304
+ elements.settingsBtn.querySelector('i').classList.remove('opacity-0');
305
+ elements.answerInput.focus();
306
+ });
307
+
308
+ // Close settings when clicking backdrop
309
+ document.getElementById('settings-backdrop').addEventListener('click', () => {
310
+ elements.settingsPanel.classList.remove('open');
311
+ document.getElementById('settings-backdrop').classList.remove('opacity-100', 'pointer-events-auto');
312
+ elements.settingsBtn.querySelector('i').classList.remove('opacity-0');
313
+ elements.answerInput.focus();
314
+ });
315
+
316
+ // Save settings
317
+ elements.saveSettings.addEventListener('click', saveSettings);
318
+
319
+ // Reset stats
320
+ elements.resetStats.addEventListener('click', resetStats);
321
+
322
+ // Mode change
323
+ elements.modeRadios.forEach(radio => {
324
+ radio.addEventListener('change', (e) => {
325
+ if (e.target.value === 'factoring') {
326
+ elements.productRangeContainer.classList.remove('hidden');
327
+ } else {
328
+ elements.productRangeContainer.classList.add('hidden');
329
+ }
330
+ });
331
+ });
332
+ }
333
+
334
+ // Save settings from form to config
335
+ function saveSettings() {
336
+ // Get mode
337
+ config.mode = document.querySelector('input[name="mode"]:checked').value;
338
+
339
+ // Get number ranges
340
+ config.multiplierMin = parseInt(elements.multiplierMin.value) || 1;
341
+ config.multiplierMax = parseInt(elements.multiplierMax.value) || 12;
342
+ config.multiplicandMin = parseInt(elements.multiplicandMin.value) || 1;
343
+ config.multiplicandMax = parseInt(elements.multiplicandMax.value) || 12;
344
+ config.productMin = parseInt(elements.productMin.value) || 10;
345
+ config.productMax = parseInt(elements.productMax.value) || 100;
346
+
347
+ // Get exclude list
348
+ const excludeStr = elements.excludeList.value.trim();
349
+ config.excludeList = excludeStr ? excludeStr.split(',').map(num => parseInt(num.trim())).filter(num => !isNaN(num)) : [];
350
+
351
+ // Get time limit
352
+ config.timeLimit = parseInt(elements.timeLimit.value) || 5;
353
+
354
+ // Save to localStorage
355
+ saveConfig();
356
+
357
+ // Close settings panel
358
+ elements.settingsPanel.classList.remove('open');
359
+ document.getElementById('settings-backdrop').classList.remove('opacity-100', 'pointer-events-auto');
360
+ elements.settingsBtn.querySelector('i').classList.remove('opacity-0');
361
+
362
+ // Restart game with new settings
363
+ resetGame();
364
+ setTimeout(() => {
365
+ elements.answerInput.focus();
366
+ elements.answerInput.select();
367
+ }, 100);
368
+ }
369
+
370
+ // Reset game stats
371
+ function resetStats() {
372
+ state.correctCount = 0;
373
+ state.incorrectCount = 0;
374
+ updateStats();
375
+ }
376
+
377
+ // Reset the game state
378
+ function resetGame() {
379
+ clearTimeout(state.timer);
380
+ state.isRunning = false;
381
+ generateQuestion();
382
+ }
383
+
384
+ // Update stats display
385
+ function updateStats() {
386
+ elements.correctCount.textContent = state.correctCount;
387
+ elements.incorrectCount.textContent = state.incorrectCount;
388
+
389
+ const total = state.correctCount + state.incorrectCount;
390
+ const accuracy = total > 0 ? Math.round((state.correctCount / total) * 100) : 0;
391
+ elements.accuracy.textContent = accuracy;
392
+ }
393
+
394
+ // Generate a new question
395
+ function generateQuestion() {
396
+ clearTimeout(state.timer);
397
+
398
+ let num1, num2, question, answer;
399
+
400
+ if (config.mode === 'multiplication') {
401
+ // Generate multiplication question
402
+ [num1, num2] = generateValidNumbers(
403
+ config.multiplierMin,
404
+ config.multiplierMax,
405
+ config.multiplicandMin,
406
+ config.multiplicandMax
407
+ );
408
+
409
+ question = `${num1} × ${num2} =`;
410
+ answer = num1 * num2;
411
+ } else {
412
+ // Generate factoring question
413
+ let attempts = 0;
414
+ const maxAttempts = 100;
415
+
416
+ while (attempts < maxAttempts) {
417
+ num1 = getRandomInt(config.multiplierMin, config.multiplierMax);
418
+ num2 = getRandomInt(config.multiplicandMin, config.multiplicandMax);
419
+
420
+ // Check if numbers are excluded
421
+ if (config.excludeList.includes(num1) || config.excludeList.includes(num2)) {
422
+ attempts++;
423
+ continue;
424
+ }
425
+
426
+ const product = num1 * num2;
427
+
428
+ // Check if product is within range
429
+ if (product >= config.productMin && product <= config.productMax) {
430
+ question = `${product} ÷ ${num1} =`;
431
+ answer = num2;
432
+ break;
433
+ }
434
+
435
+ attempts++;
436
+ }
437
+
438
+ // If we couldn't find a valid question after max attempts
439
+ if (attempts >= maxAttempts) {
440
+ question = "Couldn't generate question with current settings";
441
+ answer = null;
442
+ }
443
+ }
444
+
445
+ state.currentQuestion = question;
446
+ state.correctAnswer = answer;
447
+
448
+ elements.question.textContent = question;
449
+ elements.answerInput.value = '';
450
+ elements.feedback.textContent = '';
451
+ elements.feedback.classList.remove('show', 'text-green-400', 'text-red-400');
452
+
453
+ if (answer !== null) {
454
+ startTimer();
455
+ }
456
+ }
457
+
458
+ // Generate valid numbers that aren't in the exclude list
459
+ function generateValidNumbers(min1, max1, min2, max2) {
460
+ let num1, num2;
461
+ let attempts = 0;
462
+ const maxAttempts = 100;
463
+
464
+ do {
465
+ num1 = getRandomInt(min1, max1);
466
+ num2 = getRandomInt(min2, max2);
467
+ attempts++;
468
+
469
+ if (attempts >= maxAttempts) {
470
+ // If we can't find valid numbers after many attempts, just use any
471
+ break;
472
+ }
473
+ } while (config.excludeList.includes(num1) || config.excludeList.includes(num2));
474
+
475
+ return [num1, num2];
476
+ }
477
+
478
+ // Get random integer between min and max (inclusive)
479
+ function getRandomInt(min, max) {
480
+ min = Math.ceil(min);
481
+ max = Math.floor(max);
482
+ return Math.floor(Math.random() * (max - min + 1)) + min;
483
+ }
484
+
485
+ // Start the timer for the current question
486
+ function startTimer() {
487
+ clearTimeout(state.timer);
488
+ state.timeLeft = config.timeLimit;
489
+ state.isRunning = true;
490
+
491
+ // Update timer bar immediately
492
+ updateTimerBar();
493
+
494
+ // Start countdown
495
+ state.timer = setInterval(() => {
496
+ state.timeLeft -= 0.1;
497
+ updateTimerBar();
498
+
499
+ if (state.timeLeft <= 0) {
500
+ clearInterval(state.timer);
501
+ timeUp();
502
+ }
503
+ }, 100);
504
+ }
505
+
506
+ // Update the timer bar display
507
+ function updateTimerBar() {
508
+ const percentage = Math.max(0, (state.timeLeft / config.timeLimit) * 100);
509
+ elements.timerBar.style.width = `${percentage}%`;
510
+
511
+ // Change color based on time left
512
+ if (percentage > 50) {
513
+ elements.timerBar.className = 'timer-bar bg-blue-500 rounded-full';
514
+ } else if (percentage > 25) {
515
+ elements.timerBar.className = 'timer-bar bg-yellow-500 rounded-full';
516
+ } else {
517
+ elements.timerBar.className = 'timer-bar bg-red-500 rounded-full';
518
+ }
519
+ }
520
+
521
+ // Handle when time is up
522
+ function timeUp() {
523
+ state.isRunning = false;
524
+ state.incorrectCount++;
525
+ updateStats();
526
+
527
+ showFeedback(`Time's up! Answer: ${state.correctAnswer}`, false);
528
+
529
+ // Auto-advance after delay
530
+ setTimeout(() => {
531
+ generateQuestion();
532
+ }, 2000);
533
+ }
534
+
535
+ // Check the user's answer
536
+ function checkAnswer() {
537
+ if (!state.isRunning || state.correctAnswer === null) return;
538
+
539
+ clearTimeout(state.timer);
540
+ state.isRunning = false;
541
+
542
+ const userAnswer = parseInt(elements.answerInput.value.trim());
543
+
544
+ if (isNaN(userAnswer)) {
545
+ showFeedback('Please enter a number', false);
546
+ return;
547
+ }
548
+
549
+ if (userAnswer === state.correctAnswer) {
550
+ state.correctCount++;
551
+ showFeedback('Correct!', true);
552
+ } else {
553
+ state.incorrectCount++;
554
+ showFeedback(`Incorrect! Answer: ${state.correctAnswer}`, false);
555
+ }
556
+
557
+ updateStats();
558
+
559
+ // Auto-advance after delay
560
+ setTimeout(() => {
561
+ generateQuestion();
562
+ }, 1500);
563
+ }
564
+
565
+ // Show feedback message
566
+ function showFeedback(message, isCorrect) {
567
+ elements.feedback.textContent = message;
568
+ elements.feedback.classList.add('show');
569
+
570
+ if (isCorrect) {
571
+ elements.feedback.classList.add('text-green-400');
572
+ elements.feedback.classList.remove('text-red-400');
573
+ } else {
574
+ elements.feedback.classList.add('text-red-400');
575
+ elements.feedback.classList.remove('text-green-400');
576
+ }
577
+ }
578
+
579
+ // Initialize the game when the page loads
580
+ window.addEventListener('DOMContentLoaded', init);
581
+ </script>
582
+ <p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=LAshi/calculation" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
583
+ </html>