Map indexes to IDs

This commit is contained in:
luca0N! 2021-05-30 15:52:40 -03:00
parent b6c22ef153
commit 6e8cdd5880
Signed by: luca0N
GPG key ID: 2E7B4655CF16D7D6
2 changed files with 106 additions and 3 deletions

View file

@ -25,7 +25,7 @@
* by luca0N! <https://www.luca0n.com>
*/
let quizEl;
let quizEl, mappedIds = [];
// Attach setUpStrings() to onReady() in order to execute the main code as soon as possible. This overwrites onReady().
onReady = setUpStrings;
@ -64,12 +64,14 @@ function setUpStrings(){
itemDiv.appendChild(itemTitle);
mappedIds[x] = [];
if (contents[x].type === 'multiple' || contents[x].type === 'single'){
// Generate a checkbox for each choice.
for (let y = 0; y < contents[x].choices.length; y++){
if (contents[x].choices.length != contents[x].values.length){
if (contents[x].choices.length != contents[x].ids.length){
console.error('Unable to add choice #' + (y + 1) + ' for question #' + (x + 1) + ': ' +
contents[x].choices.length > contents[x].values.length ? 'missing values' : 'extra values found');
contents[x].choices.length > contents[x].ids.length ? 'missing ID(s)' : 'extra ID(s) found');
continue;
}
@ -83,6 +85,8 @@ function setUpStrings(){
questionLabel.htmlFor = currentId;
questionLabel.innerText = contents[x].choices[y];
mappedIds[x][y] = contents[x].ids[y];
itemDiv.append(questionInput);
itemDiv.append(questionLabel);
if (y < contents[x].choices.length)