Map indexes to IDs
This commit is contained in:
parent
b6c22ef153
commit
6e8cdd5880
2 changed files with 106 additions and 3 deletions
|
@ -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)
|
||||
|
|
Reference in a new issue