Calculate user score
This commit is contained in:
parent
6e8cdd5880
commit
bb9ec41cbd
|
@ -25,7 +25,7 @@
|
||||||
* by luca0N! <https://www.luca0n.com>
|
* 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().
|
// Attach setUpStrings() to onReady() in order to execute the main code as soon as possible. This overwrites onReady().
|
||||||
onReady = setUpStrings;
|
onReady = setUpStrings;
|
||||||
|
@ -41,7 +41,7 @@ function setUpStrings(){
|
||||||
warning.style['display'] = 'unset';
|
warning.style['display'] = 'unset';
|
||||||
// Get JSON file which contains all of the challenges required.
|
// Get JSON file which contains all of the challenges required.
|
||||||
sendGetRequest('privacy-quiz.en.json', function(text){
|
sendGetRequest('privacy-quiz.en.json', function(text){
|
||||||
let quiz = JSON.parse(text);
|
quiz = JSON.parse(text);
|
||||||
|
|
||||||
// Set up UI elements based on quiz metadata.
|
// Set up UI elements based on quiz metadata.
|
||||||
let quizTitle = document.getElementById('quiz-title');
|
let quizTitle = document.getElementById('quiz-title');
|
||||||
|
@ -112,6 +112,24 @@ function setUpStrings(){
|
||||||
let finish = document.createElement('button');
|
let finish = document.createElement('button');
|
||||||
finish.innerText = 'Finish!';
|
finish.innerText = 'Finish!';
|
||||||
finish.onclick = function(){
|
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.
|
// Hide quiz and then show the results.
|
||||||
quizEl.style['display'] = 'none';
|
quizEl.style['display'] = 'none';
|
||||||
document.getElementById('results').style['display'] = 'unset';
|
document.getElementById('results').style['display'] = 'unset';
|
||||||
|
|
Reference in New Issue