So for a school assignment I have to make an interactive quiz with javascript. That I did, the problem is that it is required for me to store all the questions in an external text file on local storage. My questions are stored in an array of objects, and I add them to radio buttons with a 'for'-loop
I googled it, but I didn't find an answer that made it clear enough for me... I understand that I can read files out, but I have no idea how I would add the questions to my existing for-loops
I'm still totally new to JS, and have no idea how to implement this
here's a code snippet, where i take the questions out of the array, and add them to the list with radio buttons
var i = 0;
var len = allQuestions.length;
function frageStellen(i){
var anzahlVarianten = allQuestions[i].choices.length;
for(var j = 0; j < anzahlVarianten; j++){
//create radio buttons
var option = document.createElement("li");
var variante = document.createElement("input");
variante.setAttribute('type', 'radio');
variante.setAttribute('name', 'gestellteFrage'+ i);
option.setAttribute('class', '.option');
//fragen-Inhalt
var inhalt = document.createTextNode(allQuestions[i].choices[j]);
myOptions.appendChild(option);
option.appendChild(variante);
option.appendChild(inhalt);
myQuestion.innerHTML = allQuestions[i].question;
}
}
Here is the link to the full code: http://jsfiddle.net/7HaCz/
please help!