I am writing a javascript program to dynamically print the elements of a multidimensional array to create a quiz. My structure is correct but I'm trying to print the 'choice' elements so they are displayed as radio buttons for the choices of each question.
Javascript:
var dataquestions = [];
dataquestions[0] = {question: "Who is the prime Minister of the United Kingdom?", choice0: "David Cameron", choice1: "Tony Blair", choice2:"Gordon Brown", answer:"David Cameron"};
dataquestions[1] = {question:"In what year was the Declaration of Independence signed?", choice0:"1985", choice1:"1492", choice2:"1776", answer:"1776"};
dataquestions[2] = {question:"Which country is in Europe?", choice0:"Pakistan", choice1:"France", choice2:"Australia", answer:"France"};
for (var i=0; i<=2; i++)
{
document.getElementById('quizcontain').innerHTML+= '<p>'+ dataquestions[i].question+'</p><br><br>';
for (var j=0; j<=2; j++){
document.getElementById('quizcontain').innerHTML+='<input type="radio" name='+j+'>'+dataquestions[i].choice+j+'<br>';
}
}
Output:
Who is the prime Minister of the United Kingdom?
undefined
undefined
undefined
In what year was the Declaration of Independence signed?
undefined
undefined
undefined
Which country is in Europe?
undefined
undefined
undefined