1
我正在爲一個叫做「構建測驗」的樹屋挑戰。我必須提出問題,根據用戶的回答,我應該顯示哪些問題他/她是否對錯。我現在特別苦惱的是理解爲什麼下面的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);