为什么这段代码不会在浏览器中提示一次?
问题描述:
我正在为一个叫做“构建测验”的树屋挑战。我必须提出问题,根据用户的回答,我应该显示哪些问题他/她是否对错。我现在特别苦恼的是理解为什么下面的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);
答
循环表达式的右括号与代码块的开始大括号之间的“for”循环中有一个分号分号。