我似乎无法弄清楚这一点。这是与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