有人可以解释为什么我的循环只显示数组的最后一个对象吗?因为我想输出我的测验的所有回答谢谢!
var allQuestions = [
{
question: "Welk kerstnummer draai jij grijs tijdens de feestdagen?",
responses: [{
text: 'Feliz Navidad',
value: 10
},
{
text: 'Baby, Its Cold Outside',
value: 6
},
var currentQuestion = 0;
var question;
var responses;
var questions = document.getElementById("question");
var quizForm = document.getElementById("choiceList");
function showQuestion() {
question = allQuestions[currentQuestion].question;
// choice = allQuestions[answers].responses.length;
questions.innerHTML = "<p>" + question + "</p>";
for (var i = 0; i < allQuestions[currentQuestion].responses.length; i++) {
responses = allQuestions[currentQuestion].responses[i].text;
quizForm.innerHTML = "<li>" + responses + "</li>";
}
}
showQuestion();