我正在为树屋做出挑战,叫做#34;建立一个测验"。我必须创建问题,并根据用户的答案,我应该显示他/她有正确和错误的问题。我现在特别挣扎的是理解为什么下面的javascript代码不会至少提出我的一个问题。 任何见解将不胜感激。
// Questions
var questions = [
['Who is the President of the U.S?', 'Donald Trump'],
['Who is the Vice President of the U.S?', 'Mike Pence'],
['Who won the Super Bowl last year?', 'Patriots']
];
//Variables go here, answer, response, question ect
var correctAnswers = 0;
var question;
var answer;
var response;
var html;
function print(message) {
document.write(message);
}
//below is how you loop the questions above
for (var i = 0; i < questions.length; i += 1); {
question = questions[i][0];
answer = questions[i][1];
response = window.prompt(question);
if (response === answer) {
correctAnswers += 1;
}
}
html = "you got" + correctAnswers + "question(s) right.";
print(html);
答案 0 :(得分:1)
&#34;&#34;&#34;&#34;中有一个流浪的分号。循环表达式的右括号和代码块的左括号之间的循环。