Fausto Busuito
commited on
Commit
·
a8edac9
1
Parent(s):
7e8a856
Application changes
Browse files- app/static/script.js +73 -6
app/static/script.js
CHANGED
@@ -224,16 +224,83 @@ document.getElementById('end-session').addEventListener('click', () => {
|
|
224 |
resultsContainer.style.display = 'block';
|
225 |
});
|
226 |
|
227 |
-
// Aggiungi l'event listener per il pulsante "Restart" (Return to Start)
|
228 |
document.getElementById('restart').addEventListener('click', () => {
|
229 |
-
// Nascondi
|
230 |
-
document.getElementById('quiz-container').style.display = 'none';
|
231 |
document.getElementById('results-container').style.display = 'none';
|
232 |
-
|
233 |
-
|
234 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
235 |
});
|
236 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
237 |
|
238 |
function updateTimer() {
|
239 |
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
|
|
|
224 |
resultsContainer.style.display = 'block';
|
225 |
});
|
226 |
|
|
|
227 |
document.getElementById('restart').addEventListener('click', () => {
|
228 |
+
// Nascondi i risultati e mostra il quiz
|
|
|
229 |
document.getElementById('results-container').style.display = 'none';
|
230 |
+
document.getElementById('quiz-container').style.display = 'block';
|
231 |
+
|
232 |
+
// Resetta tutte le variabili e gli stati
|
233 |
+
resetQuizState();
|
234 |
+
|
235 |
+
// Reset della selezione del file
|
236 |
+
document.getElementById('file-selector').value = ''; // Selezione file resettata
|
237 |
+
|
238 |
+
// Pulisce il contenuto dei risultati
|
239 |
+
document.getElementById('results-container').innerHTML = '';
|
240 |
+
|
241 |
+
// Ripristina la visualizzazione della prima domanda
|
242 |
+
loadQuestion();
|
243 |
});
|
244 |
|
245 |
+
// Funzione per reset della logica del quiz
|
246 |
+
function resetQuizState() {
|
247 |
+
currentQuestionIndex = 0; // Ripristina l'indice della domanda
|
248 |
+
userAnswers = []; // Resetta le risposte dell'utente
|
249 |
+
timer = 0; // Resetta il timer
|
250 |
+
clearInterval(timerInterval); // Ferma qualsiasi intervallo di timer in corso
|
251 |
+
|
252 |
+
// Reset della visualizzazione delle risposte
|
253 |
+
document.getElementById('question-container').innerHTML = ''; // Pulisce la domanda
|
254 |
+
document.getElementById('answers-container').innerHTML = ''; // Pulisce le risposte
|
255 |
+
document.getElementById('timer').innerText = '00:00'; // Reset timer
|
256 |
+
}
|
257 |
+
|
258 |
+
// Funzione per caricare la domanda
|
259 |
+
function loadQuestion() {
|
260 |
+
if (questions.length > 0) {
|
261 |
+
const question = questions[currentQuestionIndex];
|
262 |
+
|
263 |
+
// Mostra la domanda
|
264 |
+
const questionContainer = document.getElementById('question-container');
|
265 |
+
questionContainer.innerHTML = `<p>${question.question}</p>`;
|
266 |
+
|
267 |
+
// Mostra le risposte
|
268 |
+
const answersContainer = document.getElementById('answers-container');
|
269 |
+
answersContainer.innerHTML = '';
|
270 |
+
|
271 |
+
question.options.forEach((option, index) => {
|
272 |
+
const answerElement = document.createElement('div');
|
273 |
+
const inputType = question.correct.length > 1 ? 'checkbox' : 'radio';
|
274 |
+
answerElement.innerHTML = `
|
275 |
+
<label>
|
276 |
+
<input type="${inputType}" name="answer" value="${index}" /> ${option}
|
277 |
+
</label>
|
278 |
+
`;
|
279 |
+
answersContainer.appendChild(answerElement);
|
280 |
+
});
|
281 |
+
|
282 |
+
// Visualizza il numero di domanda
|
283 |
+
document.getElementById('question-number').innerText = `Question ${currentQuestionIndex + 1} of ${questions.length}`;
|
284 |
+
|
285 |
+
// Azzera il timer
|
286 |
+
startTimer();
|
287 |
+
}
|
288 |
+
}
|
289 |
+
|
290 |
+
// Funzione per avviare il timer
|
291 |
+
let timerInterval;
|
292 |
+
function startTimer() {
|
293 |
+
timer = 0;
|
294 |
+
clearInterval(timerInterval);
|
295 |
+
timerInterval = setInterval(() => {
|
296 |
+
timer++;
|
297 |
+
const minutes = String(Math.floor(timer / 60)).padStart(2, '0');
|
298 |
+
const seconds = String(timer % 60).padStart(2, '0');
|
299 |
+
document.getElementById('timer').innerText = `${minutes}:${seconds}`;
|
300 |
+
}, 1000);
|
301 |
+
}
|
302 |
+
|
303 |
+
|
304 |
|
305 |
function updateTimer() {
|
306 |
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
|