我似乎無法弄清楚這一點。這是與quizResult變量的問題,但我不知道如何讓程序做我想做的事情。我也厭倦了+ = 1,程序根本不會運行。 請幫忙。這個JavaScript程序爲什麼不起作用?
//Five question quiz using prompt, result at the end, and will be ranked
/*Questions*/
var question1 = prompt("What does 2 + 2 equal?");
var question2 = prompt("Name one of the five greatest rappers of all time");
var question3 = prompt("Fill in the blank- I'll be ____");
var question4 = prompt("What programming language are we using?");
var question5 = prompt("Are you alive?");
/*Counter*/
var quizResult = 0;
/*Conditionals*/
if(parseInt(question1) === 4){
var quizResult = quizResult +1;
}
if(question2.toLowerCase === "dylon"){
var quizResult = quizResult +1;
}
if(question3.toLowerCase === "back"){
var quizResult = quizResult +1;
}
if(question4.toLowerCase === "javascript"){
var quizResult = quizResult +1;
}
if(question5.toLowerCase === "yes"){
var quizResult = quizResult +1;
}
/*Display Reslut to user*/
if(quizResult === 5){
document.write("You answered " + quizResult + " correctly. You recieve the gold crown.");
}else if(quizResult >= 3 && quizResult <= 4){
document.write("You answered " + quizResult + " correctly. You recieve the silver crown.");
}else if(quizResult >= 1 && quizResult <= 2){
document.write("You answered " + quizResult + " correctly. You recieve the bronze crown.");
}else{
document.write("You answered " + quizResult + " correctly. Congratulations, you are not that bright.");
}
用'quizResult ++'替換整行,不要每次重新定義變量。 – adeneo 2014-11-06 17:58:31
'.toLowerCase'是一個功能!使用它作爲'.toLowerCase()' – Cheery 2014-11-06 17:59:19
這個問題似乎是無關緊要的,因爲它有太多的錯誤來解釋它們,你需要返回並獲得一個好的JavaScript教程。這超出了**太廣泛**。 – 2014-11-06 18:03:44