如何跟踪用户';s正确答案并在最后以javascript显示?

如何跟踪用户';s正确答案并在最后以javascript显示?,javascript,Javascript,我对javascript了解不多,我正在做一个javascript测试,我的问题显示在提示中。我需要我的测验来跟踪用户正确回答了多少个答案,并在游戏结束时输出这些答案以及正确答案的百分比。我查了一下我的问题,添加了函数returnScore(){ 警告(“您的分数为“+getScore()+”/“+tot”); } 到我的编码,它不工作 `<!DOCTYPE html> <html> <head> <title>Supernatural Trvi

我对javascript了解不多,我正在做一个javascript测试,我的问题显示在提示中。我需要我的测验来跟踪用户正确回答了多少个答案,并在游戏结束时输出这些答案以及正确答案的百分比。我查了一下我的问题,添加了函数returnScore(){ 警告(“您的分数为“+getScore()+”/“+tot”); } 到我的编码,它不工作

`<!DOCTYPE html>
<html>
<head>
<title>Supernatural Trvia Quiz</title>
<style type="text/css">
body{
    background-image : url("http://wallpapercave.com/wp/tNqlnzg.jpg");
    background-repeat : no-repeat;
    background-size: 100% 100%;    
    position:absolute; 
    margin-left: 5%;
    margin-top: 5%;
    color:white;
    font-size:20px;
    font-family:Georgia;
    font-weight: bold;
    }
</style>
<script>

i = 1 // counter variable

 var score=0
function main(){  // main part of program
if (i==1){ 
    document.view.qnum.value=i;  // puts question # in text box
    document.view.question.value ="What are the names of the main characters?\na) Sam and Bobby\nb) Sam and Dean\nc) Jess and Dean\nd) Sam and John ";

    // above code puts the question in the textarea, note the use of \n for "new line"

    correct="b"  // assigns the correct answer

    ans=prompt(i+'.) What are the names of the main characters? \na) Sam and Bobby\nb) Sam and Dean\nc) Jess and Dean\nd) Sam and John')  // gives user a chance to answer

}// end of question 1

else if (i==2){ 
    document.view.qnum.value=i;  // puts question # in text box
    document.view.question.value ="In the first episode when Sam got home, where did he find his girlfriend dead?\na) On the ceiling\nb) On the floor\nc) In bed\nd) In the kitchen ";

    // above code puts the question in the textarea, note the use of \n for "new line"

    correct="a"  // assigns the correct answer

    ans=prompt(i+'.) In the first episode when Sam got home, where did he find his girlfriend dead?\na) On the ceiling\nb) On the floor\nc) In bed\nd) In the kitchen ')  // gives user a chance to answer

}// end of question 2

else if (i==3){ 
    document.view.qnum.value=i;  // puts question # in text box
    document.view.question.value ="What is the name of Sam and Dean's father? \na) John Winchester \nb) Adam Winchester \nc) Castiel Novak \nd) Bobby Singer";

    // above code puts the question in the textarea, note the use of \n for "new line"

    correct="a"  // assigns the correct answer

    ans=prompt(i+'.) What is the name of Sam and Dean s father? \na) John Winchester \nb) Adam Winchester \nc) Castiel Novak \nd) Bobby Singer ')  // gives user a chance to answer

}// end of question 3

else if (i==4){ 
    document.view.qnum.value=i;  // puts question # in text box
    document.view.question.value ="What is Dean's favourite dessert? \na) Cake \nb) Eclair \nc) Ice cream \nd) Pie";

    // above code puts the question in the textarea, note the use of \n for "new line"

    correct="d"  // assigns the correct answer

    ans=prompt(i+'.) What is Dean s favourite dessert? \na) Cake \nb) Eclair \nc) Ice cream \nd) Pie ')  // gives user a chance to answer

}// end of question 4


else if (i==5){ 
    document.view.qnum.value=i;  // puts question # in text box
    document.view.question.value ="Who was Sam dating in the beginning of season 1? \na) Meg \nb) Madison \nc) Jessica \nd) Ruby";

    // above code puts the question in the textarea, note the use of \n for "new line"

    correct="c"  // assigns the correct answer

    ans=prompt(i+'.) Who was Sam dating in the beginning of season 1? \na) Meg \nb) Madison \nc) Jessica \nd) Ruby ')  // gives user a chance to answer

}// end of question 5

else if (i==6){ 
    document.view.qnum.value=i;  // puts question # in text box
    document.view.question.value ="In the pilot episode, who or what did the boys search for? \na) Windigo \nb) Bloody Mary \nc) Dracula \nd) The Woman in White";

    // above code puts the question in the textarea, note the use of \n for "new line"

    correct="d"  // assigns the correct answer

    ans=prompt(i+'.) In the pilot episode, who or what did the boys search for? \na) Windigo \nb) Bloody Mary \nc) Dracula \nd) The Woman in White ')  // gives user a chance to answer

}// end of question 6

else if (i==7){ 
    document.view.qnum.value=i;  // puts question # in text box
    document.view.question.value ="What is the license plate on the Impala during seasons 1 and 2? \na) KAZ-2Y5 \nb) K4Z-2Y8 \nc) KA2-ZY5 \nd) KA2-2Y9";

    // above code puts the question in the textarea, note the use of \n for "new line"

    correct="a"  // assigns the correct answer

    ans=prompt(i+'.) What is the license plate on the Impala during seasons 1 and 2? \na) KAZ-2Y5 \nb) K4Z-2Y8 \nc) KA2-ZY5 \nd) KA2-2Y9 ')  // gives user a chance to answer

}// end of question 7

else if (i==8){ 
    document.view.qnum.value=i;  // puts question # in text box
    document.view.question.value ="When is Dean's birthday? \na) July 24, 1979 \nb) June 20, 1980 \nc) January 16, 1980 \nd) January 24, 1979";

    // above code puts the question in the textarea, note the use of \n for "new line"

    correct="d"  // assigns the correct answer

    ans=prompt(i+'.) When is Dean s birthday? \na) July 24, 1979 \nb) June 20, 1980 \nc) January 16, 1980 \nd) January 24, 1979 ')  // gives user a chance to answer

}// end of question 8

else if (i==9){ 
    document.view.qnum.value=i;  // puts question # in text box
    document.view.question.value ="Who is the king of Hell? \na)  Zachariah \nb) Crowley \nc) Castiel \nd) Raphael";

    // above code puts the question in the textarea, note the use of \n for "new line"

    correct="b"  // assigns the correct answer

    ans=prompt(i+'.) Who is the king of Hell? \na)  Zachariah \nb) Crowley \nc) Castiel \nd) Raphael ')  // gives user a chance to answer

}// end of question 9

else if (i==10){ 
    document.view.qnum.value=i;  // puts question # in text box
    document.view.question.value ="What is the name of Sam and Dean's brother? \na)  Adam \nb) Kevin \nc) Castiel \nd) Bobby";

    // above code puts the question in the textarea, note the use of \n for "new line"

    correct="a"  // assigns the correct answer

    ans=prompt(i+'.) What is the name of Sam and Dean s brother? \na)  Adam \nb) Kevin \nc) Castiel \nd) Bobby ')  // gives user a chance to answer

}// end of question 10

else if (i==11){ 
    document.view.qnum.value=i;  // puts question # in text box
    document.view.question.value ="What is the name of the dogs? \na) Demon Dogs \nb) Hell Hounds \nc) Ghostfacers \nd) Dogs";

    // above code puts the question in the textarea, note the use of \n for "new line"

    correct="b"  // assigns the correct answer

    ans=prompt(i+'.) What is the name of the dogs? \na) Demon Dogs \nb) Hell Hounds \nc) Ghostfacers \nd) Dogs ')  // gives user a chance to answer

}// end of question 11

else if (i==12){ 
    document.view.qnum.value=i;  // puts question # in text box
    document.view.question.value ="Who Killed Sam & Dean's mother? \na) Crowley \nb) A demon \nc) Lucifer \nd) The yellowed eyed demon";

    // above code puts the question in the textarea, note the use of \n for "new line"

    correct="d"  // assigns the correct answer

    ans=prompt(i+'.) Who Killed Sam & Dean s mother? \na) Crowley \nb) A demon \nc) Lucifer \nd) The yellowed eyed demon ')  // gives user a chance to answer

}// end of question 12

else if (i==13){ 
    document.view.qnum.value=i;  // puts question # in text box
    document.view.question.value ="Who wants Sam's vessel? \na) Crowley \nb) Lucifer \nc) Raphael \nd) Zachariah";

    // above code puts the question in the textarea, note the use of \n for "new line"

    correct="b"  // assigns the correct answer

    ans=prompt(i+'.) Who wants Sam s vessel? \na) Crowley \nb) Lucifer \nc) Raphael \nd) Zachariah ')  // gives user a chance to answer

}// end of question 13

else if (i==14){ 
    document.view.qnum.value=i;  // puts question # in text box
    document.view.question.value ="Which actor plays Sam Winchester? \na) Jensen Ackles \nb) Mark Sheppard \nc) Jared Padalecki \nd) Osric Chau";

    // above code puts the question in the textarea, note the use of \n for "new line"

    correct="c"  // assigns the correct answer

    ans=prompt(i+'.) Which actor plays Sam Winchester? \na) Jensen Ackles \nb) Mark Sheppard \nc) Jared Padalecki \nd) Osric Chau ')  // gives user a chance to answer

}// end of question 14

else if (i==15){ 
    document.view.qnum.value=i;  // puts question # in text box
    document.view.question.value ="Which Winchester was the first to die? \na) Mary \nb) John \nc) Sam \nd) Dean";

    // above code puts the question in the textarea, note the use of \n for "new line"

    correct="a"  // assigns the correct answer

    ans=prompt(i+'.) Which Winchester was the first to die? \na) Mary \nb) John \nc) Sam \nd) Dean ')  // gives user a chance to answer

}// end of question 15

else if (i==16){ 
    document.view.qnum.value=i;  // puts question # in text box
    document.view.question.value ="What chemical compound is one of the few weaknesses of Leviathans? \na) Nitrate \nb) Borax \nc) Sulfur \nd) Ferrate";

    // above code puts the question in the textarea, note the use of \n for "new line"

    correct="b"  // assigns the correct answer

    ans=prompt(i+'.) What chemical compound is one of the few weaknesses of Leviathans? \na) Nitrate \nb) Borax \nc) Sulfur \nd) Ferrate ')  // gives user a chance to answer

}// end of question 16

else if (i==17){ 
    document.view.qnum.value=i;  // puts question # in text box
    document.view.question.value ="What chemical compound is one of the few weaknesses of Leviathans? \na) 1 \nb) 2 \nc) 3 \nd) 4";

    // above code puts the question in the textarea, note the use of \n for "new line"

    correct="c"  // assigns the correct answer

    ans=prompt(i+'.) What chemical compound is one of the few weaknesses of Leviathans? \na) 1 \nb) 2 \nc) 3 \nd) 4 ')  // gives user a chance to answer

}// end of question 17


else if (i==18){ 
    document.view.qnum.value=i;  // puts question # in text box
    document.view.question.value ="The boys have had numerous runins with a group of self-proclaimed paranormal experts who call themselves what? \na) Ghostblasters \nb) Ghostkillers \nc) Ghosthunters \nd) Ghostfacers";

    // above code puts the question in the textarea, note the use of \n for "new line"

    correct="d"  // assigns the correct answer

    ans=prompt(i+'.) The boys have had numerous runins with a group of self-proclaimed paranormal experts who call themselves what? \na) Ghostblasters \nb) Ghostkillers \nc) Ghosthunters \nd) Ghostfacers ')  // gives user a chance to answer

}// end of question 18

else if (i==19){ 
    document.view.qnum.value=i;  // puts question # in text box
    document.view.question.value ="After whom was Dean Winchester named? \na) His grandfather \nb) His grandmother \nc) His father \nd) No one";

    // above code puts the question in the textarea, note the use of \n for "new line"

    correct="b"  // assigns the correct answer

    ans=prompt(i+'.) After whom was Dean Winchester named? \na) His grandfather \nb) His grandmother \nc) His father \nd) No one ')  // gives user a chance to answer

}// end of question 19

else if (i==20){ 
    document.view.qnum.value=i;  // puts question # in text box
    document.view.question.value ="Which actor plays the character Castiel Novak?\na) Misha Collins \nb) Jim Beaver \nc) Mark Pellegrino \nd) Mark Sheppard";

    // above code puts the question in the textarea, note the use of \n for "new line"

    correct="a"  // assigns the correct answer

    ans=prompt(i+'.) Which actor plays the character Castiel Novak?\na) Misha Collins \nb) Jim Beaver \nc) Mark Pellegrino \nd) Mark Sheppard ')  // gives user a chance to answer

}// end of question 20



    document.view.go.focus();  // puts the focus on the "Next Question >" button so the enter key will activate it

    if (correct==ans){  // compares the real answer to the users answer

        document.view.question.value =" You are right!" // puts comment in textarea
score ++;       
    }

    else{
        document.view.question.value =" You are wrong" // puts comment in textarea

    }


    i++; // keeps track of number of questions asked

function returnScore(){
  alert("Your score is "+ getScore() +"/"+ tot);
}


} //end of main function


</script>
</head>
<body LINK="F7DD5E" VLINK="F7DD5E" ALINK="F7DD5E" onLoad="main()">

<FORM name="view">  
    Question: &nbsp;<input type="text" name="qnum" size="2">&nbsp;&nbsp;<input type="button" name="go" value="Next Question >" onClick=main()>
    <br><br>
    <TEXTAREA COLS=36 ROWS=9 name="question" wrap="virtual"></TEXTAREA> 
</FORM> 

</body>
</html>
`
`
超自然测试
身体{
背景图像:url(“http://wallpapercave.com/wp/tNqlnzg.jpg");
背景重复:无重复;
背景大小:100%100%;
位置:绝对位置;
左缘:5%;
利润率最高:5%;
颜色:白色;
字体大小:20px;
字体系列:格鲁吉亚;
字体大小:粗体;
}
i=1//计数器变量
风险值得分=0
函数main(){//程序的主要部分
如果(i==1){
document.view.qnum.value=i;//将问题#放入文本框
document.view.question.value=“主要角色的名字是什么?\na)萨姆和鲍比\nb)萨姆和迪安\nc)杰西和迪安\nd)萨姆和约翰”;
//上面的代码将问题放在文本区域,请注意“新行”的\n用法
correct=“b”//指定正确答案
ans=prompt(i+')。主要角色的名字是什么?\na)Sam和Bobby\nb)Sam和Dean\nc)Jess和Dean\nd)Sam和John')//让用户有机会回答
}//问题1结束
如果(i==2){
document.view.qnum.value=i;//将问题#放入文本框
document.view.question.value=“在山姆回家的第一集中,他在哪里发现他的女朋友死了?\na)在天花板上\nb)在地板上\nc)在床上\nd)在厨房里”;
//上面的代码将问题放在文本区域,请注意“新行”的\n用法
correct=“a”//指定正确答案
ans=prompt(i+)。在第一集中,当Sam到家时,他在哪里发现他的女朋友死了?\na)在天花板上\nb)在地板上\nc)在床上\nd)在厨房里]//给用户一个回答的机会
}//问题2结束
如果(i==3){
document.view.qnum.value=i;//将问题#放入文本框
document.view.question.value=“萨姆和迪安的父亲叫什么名字?\na)约翰·温切斯特\nb)亚当·温切斯特\nc)卡斯蒂尔·诺瓦克\nd)博比·辛格”;
//上面的代码将问题放在文本区域,请注意“新行”的\n用法
correct=“a”//指定正确答案
ans=prompt(i+')。萨姆和迪安的父亲叫什么名字?\na)约翰·温切斯特\nb)亚当·温切斯特\nc)卡斯蒂尔·诺瓦克\nd)鲍比·辛格]//给用户一个回答的机会
}//问题3结束
如果(i==4){
document.view.qnum.value=i;//将问题#放入文本框
document.view.question.value=“迪恩最喜欢的甜点是什么?\na)蛋糕\nb)冰激凌\nc)馅饼”;
//上面的代码将问题放在文本区域,请注意“新行”的\n用法
correct=“d”//指定正确答案
ans=prompt(i+)。迪恩最喜欢的甜点是什么?\na)蛋糕\nb)冰激凌\nc)馅饼“//让用户有机会回答
}//问题4结束
如果(i==5){
document.view.qnum.value=i;//将问题#放入文本框
document.view.question.value=“山姆在第一季开始时和谁约会?\na)梅格\nb)麦迪逊\nc)杰西卡\nd)鲁比”;
//上面的代码将问题放在文本区域,请注意“新行”的\n用法
correct=“c”//指定正确答案
ans=prompt(i+')。在第一季开始时,Sam和谁约会?\na)Meg\nb)Madison\nc)Jessica\nd)Ruby')//给用户一个回答的机会
}//问题5结束
如果(i==6){
document.view.qnum.value=i;//将问题#放入文本框
document.view.question.value=“在试播插曲中,男孩们在寻找谁或什么?\na)温迪戈\nb)血腥玛丽\nc)德古拉\nd)白衣女人”;
//上面的代码将问题放在文本区域,请注意“新行”的\n用法
correct=“d”//指定正确答案
ans=prompt(i+')。在试播集中,男孩们搜索的是谁或什么?\na)Windigo\nb)血腥玛丽\nc)德古拉\n和)白衣女人'//给用户一个回答的机会
}//问题6结束
如果(i==7){
document.view.qnum.value=i;//将问题#放入文本框
document.view.question.value=“第一季和第二季黑斑羚上的车牌是什么?\na)KAZ-2Y5\nb)K4Z-2Y8\nc)KA2-ZY5\nd)KA2-2Y9”;
//上面的代码将问题放在文本区域,请注意“新行”的\n用法
correct=“a”//指定正确答案
ans=prompt(i+')。第一季和第二季黑斑羚上的车牌是什么?\na)KAZ-2Y5\nb)K4Z-2Y8\nc)KA2-ZY5\nd)KA2-2Y9')//让用户有机会回答
}//问题7结束
如果(i==8){
document.view.qnum.value=i;//将问题#放入文本框
document.view.question.value=“院长的生日是什么时候?\na)1979年7月24日\nb)1980年6月20日\nc)1980年1月16日\nd)1979年1月24日”;
//上面的代码将问题放在文本区域,请注意“新行”的\n用法
correct=“d”//指定正确答案
ans=prompt(i+')院长的生日是什么时候?\na)1979年7月24日\nb)1980年6月20日\nc)1980年1月16日\nd)1979年1月24日’//给用户一个回答的机会
}//问题8结束
如果(i==9){
document.view.qnum.value=i;//将问题#放入文本框
document.view.question.value=“谁是地狱之王?\na)撒迦利亚\nb)克劳利\nc)卡斯蒂尔\nd)拉斐尔”;
//上面的代码将问题放在文本区域,请注意“新行”的\n用法
correct=“b”//指定正确答案
ans=prompt(i+')谁是地狱之王?\na)Zachariah\nb)Crowley\nc)Castiel\nd)Raphael')//给用户一个回答的机会
}//问题9结束
如果(i==10){
document.view.qnum.value=i;//将问题#放入文本框
文件
function returnScore(){
  alert("Your score is "+ getScore() +"/"+ tot);
}
// i is not 1 to 20, so there are no more questions
if (i > 20){

    alert("End of Game\nYour score is: "+ score + "/" + 20 + "\nYou scored: " + (score / 20) * 100 + "%" );
}