Skip to content

Commit aae3a09

Browse files
committed
Mise à jour des notes à la fin.
1 parent e601cb5 commit aae3a09

File tree

1 file changed

+39
-13
lines changed

1 file changed

+39
-13
lines changed

js/quiz.js

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,13 @@ function addEventListenerToNextButton() {
176176
//Append every object of the table to the table table-results-body in the results.html page
177177
function appendToTable(qas) {
178178

179+
var noteDisplay = document.getElementById("note-display");
180+
var noteTitle = document.createElement("h1");
181+
182+
noteDisplay.appendChild(noteTitle);
183+
noteDisplay.appendChild(document.createElement("hr"));
184+
185+
179186
//Get the table body
180187
var tableBody = document.getElementById("table-results-body");
181188
var note = 0;
@@ -196,39 +203,59 @@ function appendToTable(qas) {
196203
}
197204
var userAnswer = qas[i].getUserAnswer();
198205

206+
var chckmrk = document.createElement("input");
207+
chckmrk.setAttribute("type", "checkbox");
208+
209+
210+
199211
//if the answer = userAnswer, the cell should be green and have a checkmark icon
200212
//else the cell should be red and have a cross icon
201213
if (answer2 != undefined) {
202214
if (userAnswer != undefined) {
215+
216+
203217
if (answer.replace(/\s+/g, '') == userAnswer.replace(/\s+/g, '') || answer2.replace(/\s+/g, '') == userAnswer.replace(/\s+/g, '')) {
204218
row.setAttribute("class", "row-green");
205-
cell.innerHTML = "✔️";
219+
chckmrk.checked = true;
206220
note++;
207221
} else {
208222
row.setAttribute("class", "row-red");
209-
cell.innerHTML = "❌";
223+
chckmrk.checked = false;
210224
}
211225
} else {
212226
row.setAttribute("class", "row-red");
213-
cell.innerHTML = "❌";
227+
chckmrk.checked = false;
214228
}
215229
} else {
216230
if (userAnswer != undefined) {
217231
if (answer.replace(/\s+/g, '') == userAnswer.replace(/\s+/g, '')) {
218232
row.setAttribute("class", "row-green");
219-
cell.innerHTML = "✔️";
233+
chckmrk.checked = true;
220234
note++;
221235
} else {
222236
row.setAttribute("class", "row-red");
223-
cell.innerHTML = "❌";
237+
chckmrk.checked = false;
224238
}
225239
} else {
226240
row.setAttribute("class", "row-red");
227-
cell.innerHTML = "❌";
241+
chckmrk.checked = false;
228242
}
229243

230244
}
231245

246+
chckmrk.addEventListener('change', function() {
247+
if (this.checked) {
248+
console.log("Checkbox is checked..");
249+
note++;
250+
testNote(noteTitle, note, length);
251+
} else {
252+
console.log("Checkbox is not checked..");
253+
note--;
254+
testNote(noteTitle, note, length);
255+
}
256+
});
257+
258+
cell.appendChild(chckmrk);
232259
row.appendChild(cell);
233260
// cell = document.createElement("td");
234261
// //Set the text of the cell
@@ -273,8 +300,12 @@ function appendToTable(qas) {
273300
//Append the row to the table body
274301
tableBody.appendChild(row);
275302
}
276-
var noteDisplay = document.getElementById("note-display");
277-
var noteTitle = document.createElement("h1");
303+
304+
305+
testNote(noteTitle, note, length);
306+
}
307+
308+
function testNote(noteTitle, note, length) {
278309
noteTitle.innerHTML = note + "/" + length + " bonnes réponses (" + (note / length * 100).toFixed(2) + "%)";
279310
//Change the title attribute of the noteTitle div
280311
//Change the color of the title depending on the note
@@ -287,9 +318,4 @@ function appendToTable(qas) {
287318
}
288319

289320

290-
noteDisplay.appendChild(noteTitle);
291-
noteTitle = document.createElement("hr");
292-
noteDisplay.appendChild(noteTitle);
293-
294-
295321
}

0 commit comments

Comments
 (0)