Fausto Busuito
commited on
Commit
·
8a5b93a
1
Parent(s):
fff0efe
Application changes
Browse files- app/static/script.js +27 -10
- app/templates/index.html +1 -1
app/static/script.js
CHANGED
|
@@ -97,8 +97,9 @@ document.getElementById('prev').addEventListener('click', () => {
|
|
| 97 |
|
| 98 |
document.getElementById('end-session').addEventListener('click', () => {
|
| 99 |
let correctCount = 0;
|
|
|
|
|
|
|
| 100 |
|
| 101 |
-
// Crea la tabella dei risultati
|
| 102 |
const resultsTable = document.createElement('table');
|
| 103 |
resultsTable.style.width = '100%';
|
| 104 |
resultsTable.style.borderCollapse = 'collapse';
|
|
@@ -139,12 +140,18 @@ document.getElementById('end-session').addEventListener('click', () => {
|
|
| 139 |
const correctAnswerCell = document.createElement('td');
|
| 140 |
if (userAnswers[index].length === 0) {
|
| 141 |
correctAnswerCell.innerText = 'No answer';
|
|
|
|
| 142 |
} else {
|
| 143 |
const correctAnswersText = question.correct.map(letter => {
|
| 144 |
const optionIndex = letter.charCodeAt(0) - 65; // A = 0, B = 1, C = 2, ...
|
| 145 |
return question.options[optionIndex];
|
| 146 |
}).join(', ');
|
| 147 |
correctAnswerCell.innerText = correctAnswersText;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
}
|
| 149 |
correctAnswerCell.style.border = '1px solid #ddd';
|
| 150 |
correctAnswerCell.style.padding = '10px';
|
|
@@ -164,7 +171,6 @@ document.getElementById('end-session').addEventListener('click', () => {
|
|
| 164 |
if (isCorrect) {
|
| 165 |
statusCell.innerText = 'Correct';
|
| 166 |
statusCell.style.color = 'green';
|
| 167 |
-
correctCount++;
|
| 168 |
} else {
|
| 169 |
statusCell.innerText = 'Incorrect';
|
| 170 |
statusCell.style.color = 'red';
|
|
@@ -178,16 +184,26 @@ document.getElementById('end-session').addEventListener('click', () => {
|
|
| 178 |
});
|
| 179 |
|
| 180 |
// Calcola lo score
|
| 181 |
-
const
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
const resultsContainer = document.getElementById('results-container');
|
| 189 |
resultsContainer.innerHTML = ''; // Pulisci i risultati precedenti
|
| 190 |
-
resultsContainer.appendChild(
|
| 191 |
resultsContainer.appendChild(resultsTable);
|
| 192 |
|
| 193 |
// Mostra il contenitore dei risultati e nascondi il quiz
|
|
@@ -200,6 +216,7 @@ document.getElementById('end-session').addEventListener('click', () => {
|
|
| 200 |
|
| 201 |
|
| 202 |
|
|
|
|
| 203 |
document.getElementById('restart').addEventListener('click', () => {
|
| 204 |
document.getElementById('results-container').style.display = 'none';
|
| 205 |
document.getElementById('file-selection').style.display = 'block';
|
|
|
|
| 97 |
|
| 98 |
document.getElementById('end-session').addEventListener('click', () => {
|
| 99 |
let correctCount = 0;
|
| 100 |
+
let incorrectCount = 0;
|
| 101 |
+
let unansweredCount = 0;
|
| 102 |
|
|
|
|
| 103 |
const resultsTable = document.createElement('table');
|
| 104 |
resultsTable.style.width = '100%';
|
| 105 |
resultsTable.style.borderCollapse = 'collapse';
|
|
|
|
| 140 |
const correctAnswerCell = document.createElement('td');
|
| 141 |
if (userAnswers[index].length === 0) {
|
| 142 |
correctAnswerCell.innerText = 'No answer';
|
| 143 |
+
unansweredCount++; // Aumenta il contatore delle risposte non date
|
| 144 |
} else {
|
| 145 |
const correctAnswersText = question.correct.map(letter => {
|
| 146 |
const optionIndex = letter.charCodeAt(0) - 65; // A = 0, B = 1, C = 2, ...
|
| 147 |
return question.options[optionIndex];
|
| 148 |
}).join(', ');
|
| 149 |
correctAnswerCell.innerText = correctAnswersText;
|
| 150 |
+
if (JSON.stringify(userAnswers[index].sort()) === JSON.stringify(question.correct.sort().map(letter => letter.charCodeAt(0) - 65))) {
|
| 151 |
+
correctCount++; // Aumenta il contatore delle risposte corrette
|
| 152 |
+
} else {
|
| 153 |
+
incorrectCount++; // Aumenta il contatore delle risposte sbagliate
|
| 154 |
+
}
|
| 155 |
}
|
| 156 |
correctAnswerCell.style.border = '1px solid #ddd';
|
| 157 |
correctAnswerCell.style.padding = '10px';
|
|
|
|
| 171 |
if (isCorrect) {
|
| 172 |
statusCell.innerText = 'Correct';
|
| 173 |
statusCell.style.color = 'green';
|
|
|
|
| 174 |
} else {
|
| 175 |
statusCell.innerText = 'Incorrect';
|
| 176 |
statusCell.style.color = 'red';
|
|
|
|
| 184 |
});
|
| 185 |
|
| 186 |
// Calcola lo score
|
| 187 |
+
const totalQuestions = questions.length;
|
| 188 |
+
const score = (correctCount / totalQuestions) * 100;
|
| 189 |
+
|
| 190 |
+
// Mostra il punteggio con i dettagli
|
| 191 |
+
const scoreDetails = document.createElement('div');
|
| 192 |
+
scoreDetails.style.marginBottom = '20px';
|
| 193 |
+
|
| 194 |
+
scoreDetails.innerHTML = `
|
| 195 |
+
<h3>Quiz Results</h3>
|
| 196 |
+
<p><strong>Total Questions:</strong> ${totalQuestions}</p>
|
| 197 |
+
<p><strong>Correct Answers:</strong> ${correctCount}</p>
|
| 198 |
+
<p><strong>Incorrect Answers:</strong> ${incorrectCount}</p>
|
| 199 |
+
<p><strong>Unanswered Questions:</strong> ${unansweredCount}</p>
|
| 200 |
+
<p><strong>Your score:</strong> ${score.toFixed(2)}%</p>
|
| 201 |
+
`;
|
| 202 |
+
|
| 203 |
+
// Aggiungi i dettagli del punteggio e la tabella ai risultati
|
| 204 |
const resultsContainer = document.getElementById('results-container');
|
| 205 |
resultsContainer.innerHTML = ''; // Pulisci i risultati precedenti
|
| 206 |
+
resultsContainer.appendChild(scoreDetails);
|
| 207 |
resultsContainer.appendChild(resultsTable);
|
| 208 |
|
| 209 |
// Mostra il contenitore dei risultati e nascondi il quiz
|
|
|
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
+
|
| 220 |
document.getElementById('restart').addEventListener('click', () => {
|
| 221 |
document.getElementById('results-container').style.display = 'none';
|
| 222 |
document.getElementById('file-selection').style.display = 'block';
|
app/templates/index.html
CHANGED
|
@@ -22,7 +22,7 @@
|
|
| 22 |
<div id="quiz-container" style="display: none;">
|
| 23 |
<div id="question-container">
|
| 24 |
<h2 id="question-number"></h2>
|
| 25 |
-
<p id="timer">Time:
|
| 26 |
<h2 id="question" style="font-weight: normal;"></h2>
|
| 27 |
<div id="options"></div>
|
| 28 |
<div id="navigation">
|
|
|
|
| 22 |
<div id="quiz-container" style="display: none;">
|
| 23 |
<div id="question-container">
|
| 24 |
<h2 id="question-number"></h2>
|
| 25 |
+
<p id="timer">Time: 00:00:00</p>
|
| 26 |
<h2 id="question" style="font-weight: normal;"></h2>
|
| 27 |
<div id="options"></div>
|
| 28 |
<div id="navigation">
|