Calculate user score

This commit is contained in:
luca0N! 2021-05-30 16:05:58 -03:00
parent 6e8cdd5880
commit bb9ec41cbd
Signed by: luca0N
GPG Key ID: 2E7B4655CF16D7D6
1 changed files with 20 additions and 2 deletions

View File

@ -25,7 +25,7 @@
* by luca0N! <https://www.luca0n.com>
*/
let quizEl, mappedIds = [];
let quiz, quizEl, mappedIds = [];
// Attach setUpStrings() to onReady() in order to execute the main code as soon as possible. This overwrites onReady().
onReady = setUpStrings;
@ -41,7 +41,7 @@ function setUpStrings(){
warning.style['display'] = 'unset';
// Get JSON file which contains all of the challenges required.
sendGetRequest('privacy-quiz.en.json', function(text){
let quiz = JSON.parse(text);
quiz = JSON.parse(text);
// Set up UI elements based on quiz metadata.
let quizTitle = document.getElementById('quiz-title');
@ -112,6 +112,24 @@ function setUpStrings(){
let finish = document.createElement('button');
finish.innerText = 'Finish!';
finish.onclick = function(){
// Calculate the results.
let score = 0;
// Retrieve choices.
let contents = quiz.contents;
let choices = [];
for (let x = 0; x < contents.length; x++){
choices[x] = [];
for (let y = 0; y < contents[x].choices.length; y++){
let currentEl = document.getElementById('sec.' + x + '.ch.' + y); // current choice element
// Is it checked?
if (currentEl.checked){
// Get the ID
//choices[x].push(mappedIds[x][y]);
score += quiz.reports[mappedIds[x][y]].points;
}
}
}
// Hide quiz and then show the results.
quizEl.style['display'] = 'none';
document.getElementById('results').style['display'] = 'unset';