我有一个包含两个对象的数组。当用户按下按钮时,我希望显示特定对象属性的下一个值。
这是我的数组:
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"
}];
当按下按钮时,我想显示下一个“问题”实例。
这是我切换问题的功能:
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;
}