I have an array of two objects. When the user presses a button, I would like for the next value of a specific object property to be displayed.
Here is my array:
var allQuestions = [{
question: "This is question number one",
choices: ["one", "two", "three", "four"],
correctAnswer: "two"
}, {
question: "This is question number two",
choices: ["dog", "cat", "bear", "lion"],
correctAnswer: "bear"
}];
When the button is pressed, I would like for the next instance of "question" to be displayed.
Here is my function to switch out the question:
function switchQuestion() {
var singleQuestion = 0;
if(singleQuestion >= allQuestions.length) {
singleQuestion == 0;
} else {
singleQuestion == ""; // not sure what should go here
}
document.getElementById('question').innerHTML = allQuestions[singleQuestion].question;
}