From 8bd6b16f7135ce9e99d3e44f3da0233912869ecf Mon Sep 17 00:00:00 2001 From: luca0N! Date: Sun, 30 May 2021 16:31:16 -0300 Subject: [PATCH] Add grade calculation algorithm --- privacy-quiz.en.json | 9 +++++++++ res/Stairway-js.css | 1 + res/js/main.js | 21 ++++++++++++++++++++- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/privacy-quiz.en.json b/privacy-quiz.en.json index a26e3a6..1101e42 100644 --- a/privacy-quiz.en.json +++ b/privacy-quiz.en.json @@ -18,6 +18,15 @@ "section.multiple.points.max": 10, "section.multiple.points.min": -10 }, + "threshold":{ + "s.min": 10, + "a.min": 8, + "b.min": 4, + "c.min": 0, + "d.min": -3, + "e.min": -5, + "f.min": -8 + }, "contents":[ { diff --git a/res/Stairway-js.css b/res/Stairway-js.css index eace6e7..04bf285 100644 --- a/res/Stairway-js.css +++ b/res/Stairway-js.css @@ -42,6 +42,7 @@ body { } .badge { + display: none; padding: 14px; font-weight: bold; font-size: 32pt; diff --git a/res/js/main.js b/res/js/main.js index ee2601d..acb7547 100644 --- a/res/js/main.js +++ b/res/js/main.js @@ -124,12 +124,31 @@ function setUpStrings(){ // Is it checked? if (currentEl.checked){ // Get the ID - //choices[x].push(mappedIds[x][y]); + choices[x].push(mappedIds[x][y]); score += quiz.reports[mappedIds[x][y]].points; } } } + // Calculate the grade + let grade; + if (score > quiz.threshold['a.min']) + grade = 's'; + else if (score > quiz.threshold['b.min']) + grade = 'a' + else if (score > quiz.threshold['c.min']) + grade = 'b' + else if (score > quiz.threshold['d.min']) + grade = 'c' + else if (score > quiz.threshold['e.min']) + grade = 'd' + else if (score > quiz.threshold['b.min']) + grade = 'e'; + else grade = 'f'; + + // Display the grade X badge element (unset its 'none' display value) + document.getElementById('badge-' + grade).style['display'] = 'unset'; + // Hide quiz and then show the results. quizEl.style['display'] = 'none'; document.getElementById('results').style['display'] = 'unset';