Fausto Busuito commited on
Commit
90e32d4
1 Parent(s): 69a841f

Application changes

Browse files
Files changed (2) hide show
  1. app/static/script.js +82 -8
  2. app/static/style.css +31 -0
app/static/script.js CHANGED
@@ -91,18 +91,92 @@ document.getElementById('prev').addEventListener('click', () => {
91
  displayQuestion();
92
  });
93
 
94
- document.getElementById('end-session').addEventListener('click', async () => {
95
- const response = await fetch('/submit_results', {
96
- method: 'POST',
97
- headers: { 'Content-Type': 'application/json' },
98
- body: JSON.stringify({ questions, user_answers: userAnswers })
 
 
 
 
 
 
 
 
 
 
 
99
  });
100
- const result = await response.json();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101
  document.getElementById('quiz-container').style.display = 'none';
102
- document.getElementById('results-container').style.display = 'block';
103
- document.getElementById('score').innerText = `Your score: ${result.score.toFixed(2)}%`;
104
  });
105
 
 
106
  document.getElementById('restart').addEventListener('click', () => {
107
  document.getElementById('results-container').style.display = 'none';
108
  document.getElementById('file-selection').style.display = 'block';
 
91
  displayQuestion();
92
  });
93
 
94
+ document.getElementById('end-session').addEventListener('click', () => {
95
+ let correctCount = 0;
96
+
97
+ const resultsTable = document.createElement('table');
98
+ resultsTable.style.width = '100%';
99
+ resultsTable.style.borderCollapse = 'collapse';
100
+
101
+ // Crea l'intestazione della tabella
102
+ const headerRow = document.createElement('tr');
103
+ ['Question', 'Your Answer', 'Correct Answer', 'Status'].forEach(header => {
104
+ const th = document.createElement('th');
105
+ th.innerText = header;
106
+ th.style.border = '1px solid #ddd';
107
+ th.style.padding = '10px';
108
+ th.style.backgroundColor = '#f4f4f4';
109
+ headerRow.appendChild(th);
110
  });
111
+ resultsTable.appendChild(headerRow);
112
+
113
+ questions.forEach((question, index) => {
114
+ const row = document.createElement('tr');
115
+
116
+ // Colonna domanda
117
+ const questionCell = document.createElement('td');
118
+ questionCell.innerText = question.question;
119
+ questionCell.style.border = '1px solid #ddd';
120
+ questionCell.style.padding = '10px';
121
+ row.appendChild(questionCell);
122
+
123
+ // Colonna risposta dell'utente
124
+ const userAnswerCell = document.createElement('td');
125
+ const userAnswersText = userAnswers[index].length
126
+ ? userAnswers[index].map(ansIndex => question.options[ansIndex]).join(', ')
127
+ : 'No answer';
128
+ userAnswerCell.innerText = userAnswersText;
129
+ userAnswerCell.style.border = '1px solid #ddd';
130
+ userAnswerCell.style.padding = '10px';
131
+ row.appendChild(userAnswerCell);
132
+
133
+ // Colonna risposta corretta
134
+ const correctAnswerCell = document.createElement('td');
135
+ const correctAnswersText = question.correct.map(ansIndex => question.options[ansIndex]).join(', ');
136
+ correctAnswerCell.innerText = correctAnswersText;
137
+ correctAnswerCell.style.border = '1px solid #ddd';
138
+ correctAnswerCell.style.padding = '10px';
139
+ correctAnswerCell.style.backgroundColor = '#d4edda'; // Verde chiaro per evidenziare la risposta corretta
140
+ row.appendChild(correctAnswerCell);
141
+
142
+ // Colonna stato
143
+ const statusCell = document.createElement('td');
144
+ if (userAnswers[index].length === 0) {
145
+ statusCell.innerText = 'Not answered';
146
+ statusCell.style.color = 'orange';
147
+ } else if (
148
+ JSON.stringify(userAnswers[index].sort()) === JSON.stringify(question.correct.sort())
149
+ ) {
150
+ statusCell.innerText = 'Correct';
151
+ statusCell.style.color = 'green';
152
+ correctCount++;
153
+ } else {
154
+ statusCell.innerText = 'Incorrect';
155
+ statusCell.style.color = 'red';
156
+ }
157
+ statusCell.style.border = '1px solid #ddd';
158
+ statusCell.style.padding = '10px';
159
+ row.appendChild(statusCell);
160
+
161
+ resultsTable.appendChild(row);
162
+ });
163
+
164
+ // Calcola lo score
165
+ const score = (correctCount / questions.length) * 100;
166
+
167
+ // Mostra il punteggio
168
+ document.getElementById('score').innerText = `Your score: ${score.toFixed(2)}%`;
169
+
170
+ // Aggiungi la tabella ai risultati
171
+ const resultsContainer = document.getElementById('results-container');
172
+ resultsContainer.appendChild(resultsTable);
173
+
174
+ // Mostra il contenitore dei risultati e nascondi il quiz
175
  document.getElementById('quiz-container').style.display = 'none';
176
+ resultsContainer.style.display = 'block';
 
177
  });
178
 
179
+
180
  document.getElementById('restart').addEventListener('click', () => {
181
  document.getElementById('results-container').style.display = 'none';
182
  document.getElementById('file-selection').style.display = 'block';
app/static/style.css CHANGED
@@ -79,3 +79,34 @@ button#restart {
79
  button#restart:hover {
80
  background-color: #218838;
81
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
  button#restart:hover {
80
  background-color: #218838;
81
  }
82
+
83
+ table {
84
+ width: 100%;
85
+ border-collapse: collapse;
86
+ margin-top: 20px;
87
+ }
88
+
89
+ th, td {
90
+ border: 1px solid #ddd;
91
+ padding: 10px;
92
+ text-align: left;
93
+ }
94
+
95
+ th {
96
+ background-color: #f4f4f4;
97
+ }
98
+
99
+ td.correct {
100
+ background-color: #d4edda;
101
+ color: #155724;
102
+ }
103
+
104
+ td.incorrect {
105
+ background-color: #f8d7da;
106
+ color: #721c24;
107
+ }
108
+
109
+ td.not-answered {
110
+ background-color: #fff3cd;
111
+ color: #856404;
112
+ }