Currently working on a quiz at the moment in Javascript where the question and answers are in a nested JSON data structure. My structure looks something like this:
var quizContent = [
{
"question": "Why is the sky blue?",
"answers": [
{ "answer": "Blue light is scattered in all directions by the tiny molecules of air in Earth's atmosphere." },
{ "answer": "Idk dude" },
{ "answer": "google.com" },
{ "answer": "It just is." }
]
},
{
"question": "Why did the chicken cross the road?",
"answers": [
{ "answer": "To get to the other side." },
{ "answer": "Obama amiriteeee" },
{ "answer": "To escape genocide. "},
{ "answer": "To find itself." }
]
}
]
Obviously this is a somewhat comical approach, but I'm a little stuck on the logic of getting the values for the questions followed by the available answers.
For now I'll just show the progress through log console.log statements.
for (var i = 0; i < quizContent.length; i++){
var obj = quizContent[i];
for (var key in obj) {
console.log(obj[key]);
}
}
With this seems to get sort of what I need but eventually I'll need to go a bit further and individually put the questions in header tags as well as the answers in list items so having that control is important.
Any input would be greatly appreciated. Thank you in advance.