From aae3a09b8ccaaa4ffa337c17ed453bbc87f8d822 Mon Sep 17 00:00:00 2001 From: Ttiki Date: Sun, 11 Dec 2022 15:57:04 +0100 Subject: [PATCH] =?UTF-8?q?Mise=20=C3=A0=20jour=20des=20notes=20=C3=A0=20l?= =?UTF-8?q?a=20fin.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/quiz.js | 52 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/js/quiz.js b/js/quiz.js index b437cda..cd62fcc 100644 --- a/js/quiz.js +++ b/js/quiz.js @@ -176,6 +176,13 @@ function addEventListenerToNextButton() { //Append every object of the table to the table table-results-body in the results.html page function appendToTable(qas) { + var noteDisplay = document.getElementById("note-display"); + var noteTitle = document.createElement("h1"); + + noteDisplay.appendChild(noteTitle); + noteDisplay.appendChild(document.createElement("hr")); + + //Get the table body var tableBody = document.getElementById("table-results-body"); var note = 0; @@ -196,39 +203,59 @@ function appendToTable(qas) { } var userAnswer = qas[i].getUserAnswer(); + var chckmrk = document.createElement("input"); + chckmrk.setAttribute("type", "checkbox"); + + + //if the answer = userAnswer, the cell should be green and have a checkmark icon //else the cell should be red and have a cross icon if (answer2 != undefined) { if (userAnswer != undefined) { + + if (answer.replace(/\s+/g, '') == userAnswer.replace(/\s+/g, '') || answer2.replace(/\s+/g, '') == userAnswer.replace(/\s+/g, '')) { row.setAttribute("class", "row-green"); - cell.innerHTML = "✔️"; + chckmrk.checked = true; note++; } else { row.setAttribute("class", "row-red"); - cell.innerHTML = "❌"; + chckmrk.checked = false; } } else { row.setAttribute("class", "row-red"); - cell.innerHTML = "❌"; + chckmrk.checked = false; } } else { if (userAnswer != undefined) { if (answer.replace(/\s+/g, '') == userAnswer.replace(/\s+/g, '')) { row.setAttribute("class", "row-green"); - cell.innerHTML = "✔️"; + chckmrk.checked = true; note++; } else { row.setAttribute("class", "row-red"); - cell.innerHTML = "❌"; + chckmrk.checked = false; } } else { row.setAttribute("class", "row-red"); - cell.innerHTML = "❌"; + chckmrk.checked = false; } } + chckmrk.addEventListener('change', function() { + if (this.checked) { + console.log("Checkbox is checked.."); + note++; + testNote(noteTitle, note, length); + } else { + console.log("Checkbox is not checked.."); + note--; + testNote(noteTitle, note, length); + } + }); + + cell.appendChild(chckmrk); row.appendChild(cell); // cell = document.createElement("td"); // //Set the text of the cell @@ -273,8 +300,12 @@ function appendToTable(qas) { //Append the row to the table body tableBody.appendChild(row); } - var noteDisplay = document.getElementById("note-display"); - var noteTitle = document.createElement("h1"); + + + testNote(noteTitle, note, length); +} + +function testNote(noteTitle, note, length) { noteTitle.innerHTML = note + "/" + length + " bonnes réponses (" + (note / length * 100).toFixed(2) + "%)"; //Change the title attribute of the noteTitle div //Change the color of the title depending on the note @@ -287,9 +318,4 @@ function appendToTable(qas) { } - noteDisplay.appendChild(noteTitle); - noteTitle = document.createElement("hr"); - noteDisplay.appendChild(noteTitle); - - } \ No newline at end of file