【发布时间】:2023-01-26 04:12:18
【问题描述】:
在这里你可以看到我的代码我有问题只显示 1 个警告框,即使我把 index++。我的问题的解决方案是什么。
我的代码
var questions = [
{
text: "Da li je javascript dobar jezik",
correctAnswer : true
},
{
text: "Da li je css programski jezik",
correctAnswer : true
},
{
text: "Da li je php programski jezik",
correctAnswer: true
}
]
var index = 0;
var score = 0;
function quiz(){
var quizQuestion = confirm(questions[index].text);
if (quizQuestion === questions[index].correctAnswer){
score++;
}
index++;
if (index == questions[index]){
index=0;
}
}
quiz();
我希望显示 3 个警告框,但只显示一个
【问题讨论】:
-
confirm只被调用过一次。你是不是想写一个环形某处? -
每次你打电话给
quiz(),它都会问下一个问题。但是你只调用一次。
标签: javascript javascript-objects