I'm making a Trivia game and have an object full of questions and answers. I want to display the first question and the choices users have on the screen. After they guess, the program displays the second question.
This is what I have so far:
var qAndA = {
q1: {
question: "What is the capital of nevada",
choices:["Reno","Carson City","Las Vegas", "Boulder City"]
},
q2:{
question: "What is the capital of Oregon?",
choices:["Salem","Portland","Eugene","Bend"]
},
q3:{
question: "What is the capital of Vermont?",
choices:["Burlington","Bennington","Stowe","Montpelier"]
},
};
function questionsAnswers(){
timer();
//This Is Where I want To Use A Loop Rather Than Writing Out ".q1.question"
$("#main").append(qAndA.q1.question);
}
Is there a way to target a specific object in the array without having to write qAndA.q1.question so I don't have to write it out for each individual question (Perhaps some sort of loop to do this)?