Embarking on a project to develop a quiz in javascript, I am starting with an array that holds the questions as anonymous objects.
var allQuestions = [{
"question": "Who was Luke's wingman in the battle at Hoth?",
"choices": ["Dak", "Biggs", "Wedge", "fx-7"],
"correctAnswer": 0},
{
"question": "What is the registry of the Starship Reliant?",
"choices": [ "NX-01", "NCC-1864", "NCC-1701", "NCC-2000"],
"correctAnswer": 1}...etc.
My goal now is to iterate through these questions and display them in the DOM.
var output = '';
for (key in allQuestions[0]) {
output += '<li>' + allQuestions[0] + '</li>';
}
var update = document.getElementById("question");
update.innerHTML = output;
However, when I try this, I only see:
[object Object]
[object Object]
[object Object]
Eventually, I aim to sync up 'question' and 'choices' to populate corresponding elements on the page like so:
<h2>question</h2> //question from object
<ul id="question">
<li>choice</li> //choice from object
<li>choice</li>
<li>choice</li>
<li>choice</li>