关于我的javascript测试的特定查询

关于我的javascript测试的特定查询,javascript,Javascript,下午好。我的问答题很具体。有一件事我真的需要帮助。如果您正确回答了一个问题,请返回该问题,然后单击“下一步”,它将再次添加到您的总分中!所以你可以得到无限多的点数。我对如何着手解决这个问题感到困惑。我是个业余爱好者。请花点时间帮忙。上次它关门了,我没有得到任何指导 <!DOCTYPE HTML> <html> <head> <title>Aldine Assessment</title> <meta charse

下午好。我的问答题很具体。有一件事我真的需要帮助。如果您正确回答了一个问题,请返回该问题,然后单击“下一步”,它将再次添加到您的总分中!所以你可以得到无限多的点数。我对如何着手解决这个问题感到困惑。我是个业余爱好者。请花点时间帮忙。上次它关门了,我没有得到任何指导

<!DOCTYPE HTML>
<html>

<head>
    <title>Aldine Assessment</title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="style.css">


<script type = "text/javascript">
    var quiz = [
            {
                "question"      :   "&nbsp Q1: What is the name of this school district?",
                "choices"       :   [   "&nbsp This is Aldine Independent School District.",
                                        "&nbsp This is Spring Independent School District.",
                                        "&nbsp This is Klein Independent School District.",
                                        "&nbsp This is Houston Independent School District."],
                "correct"       :   "&nbsp This is Aldine Independent School District.", },
            {
                "question"      :   "&nbsp Q2: What city are we currently located in ?",
                "choices"       :   [   "&nbsp We are currently located in the city of Spring.",
                                        "&nbsp We are currently located in the city of Houston.",
                                        "&nbsp We are currently located in the city of Dallas.",
                                        "&nbsp We are currently located in the city of San Antonio." ],
                "correct"       :   "&nbsp We are currently located in the city of Houston.",},
            {
                "question"      :   "&nbsp Q3:What state are we currently located in?",
                "choices"       :   [   "&nbsp We are currently located in the state of Texas.",
                                        "&nbsp We are currently located in the state of Louisiana.",
                                        "&nbsp We are currently located in the state of Atlanta.",
                                        "&nbsp We are currently located in the state of Florida."],
                "correct"       :   "&nbsp We are currently located in the state of Texas.",},
            {   
                "question"      :   "&nbsp Q4:What Department are we currently in?",
                "choices"       :   [
                                        "&nbsp We are part of the Financial Services Department.",
                                        "&nbsp We are part of the Child Nutrition Department",
                                        "&nbsp We are part of the Technology Services Department",
                                        "&nbsp We are part of the Child Development Department"],

                "correct"       :   "&nbsp We are part of the Technology Services Department",},
            {   
                "question"      :   "&nbsp Q5:What month are we currently in?",
                "choices"       :   [
                                        "&nbsp We are currently in the month of June",
                                        "&nbsp We are currently in the month of July",
                                        "&nbsp We are currently in the month of August",
                                        "&nbsp We are currently in the month of September"
                                    ],
                "correct"       :   "&nbsp We are currently in the month of June",},
 ];

        var currentQuestion = 0;
        var score = 0;
        var askingQuestion = true;
        var radioAnswer= new Array();



        function loadQuestion(){
            //---------------set temporary variable for creating radio buttons-------------------------
            var radioButton;
            //---------------clear out radio buttons from previous question----------------------------
            document.getElementById('content').innerHTML = "";
            //---------------loop through choices, and create radio buttons----------------------------
            for(var i = 0; i < quiz[currentQuestion]["choices"].length; i++){
                radioButton  = document.createElement('input');
                radioButton.type = 'radio';
                radioButton.name = 'quiz'+currentQuestion;
                radioButton.id = 'choice'+ (i+1);
                if (radioAnswer[currentQuestion] == i)
                    {
                    radioButton.checked = true; 
                    }
                radioButton.value = quiz[currentQuestion]["choices"][i];
          //-------------------create label tag, which hold the actual text of the choices--------------
                var label = document.createElement('label');
                label.setAttribute('for','choice'+ (i+1));
                label.innerHTML = quiz[currentQuestion]["choices"][i];
          //-------------------------create a <br> tag to separate options-------------------------------
                var br = document.createElement('br');
                //attach them to content. Attach br tag, then label, then radio button

                document.getElementById('content').insertBefore(br, null);
                document.getElementById('content').insertBefore(label, br);
                document.getElementById('content').insertBefore(radioButton, label);
            }
        //----------------------------------load the question--------------------------------------------
            document.getElementById('question').innerHTML = quiz[currentQuestion]["question"];
        //---------------------------setup score for first time------------------------------------------
            if(currentQuestion == 0){
                document.getElementById('score').innerHTML = '<p>Score: 0 right answers out of ' + quiz.length +' possible</p>';
            }
        }

        function previous(){
        if(currentQuestion < quiz.length - 1){
                    currentQuestion--;
                    loadQuestion();
                } else {
                    showFinalResults();
                }
        }

        function checkAnswer(){

        //------------------------are we asking a question, or proceeding to next question?------------------
            if(askingQuestion){
        //---change button text to next question, so next time they click it, it goes to next question-------
                document.getElementById('check').innerHTML = 'Next Question';
                askingQuestion = false;
        //-------------------------determine which radio button they clicked---------------------------------
                var userpick;
                var correctIndex;
                var radios = document.getElementsByName('quiz'+currentQuestion);
                for(var i=0; i < radios.length; i++){
                    if(radios[i].checked){ //if this radio button is checked
                        userpick = radios[i].value;
                        radioAnswer[currentQuestion]= i;
                    }
        //-----------------------------------get index of correct answer-------------------------------------
                    if(radios[i].value == quiz[currentQuestion]["correct"]){
                        correctIndex = i;
                    }
                }
        //----------------------------set the color if they got it right, or wrong----------------------------
                if(userpick == quiz[currentQuestion]["correct"]){
                    score++;
                    document.getElementsByTagName('label')[correctIndex].style.color = "green";
                    document.getElementsByTagName('label')[correctIndex].style.fontWeight = "bold";
                } else {
                    document.getElementsByTagName('label')[correctIndex].style.color = "red";
                    document.getElementsByTagName('label')[correctIndex].style.fontWeight = "bold"; 
                }
                document.getElementById('score').innerHTML = '<p>Score: '+ score +' right answers out of ' + quiz.length +' possible</p>';
                } else { //reset form and move to next question
        //---------------------------------setting up so user can ask a question--------------------------------
                askingQuestion = true;
        //-------------------------------change button text back to 'submit answer'-----------------------------
                document.getElementById('check').innerHTML = 'Submit Answer';
        //-----------------------if we're not on last question, increase question number-------------------------
                if(currentQuestion < quiz.length - 1){
                    currentQuestion++;
                    loadQuestion();
                } else {
                    showFinalResults();
                }
            }
        }

        function showFinalResults(){

            document.getElementById('content').innerHTML = '<h2>You Completed The Quiz</h2>';
            document.getElementById('content').innerHTML += '<p>Below are your results:</p>';
            document.getElementById('content').innerHTML += '<h2>' + score + ' out of ' + quiz.length + ' questions, ' + Math.round(score/quiz.length * 100) + '%<h2>';
            //-------------------------------delete the button------------------------------------------------------
            var button = document.getElementById('check');
            button.parentNode.removeChild(button); //js requires you to delete elements from the parent
            //--------------------------------remove question-------------------------------------------------------
            document.getElementById('question').innerHTML = "";
        }
        window.onload = loadQuestion;
    </script>

</head>
<body>
<div id = "box" class = "unhidden">

    <h2>This Is A Quiz Provided By Aldine ISD</h2>
    <h4> There will be no points awarded for unanswered questions.</h4>


    <div style="position:absolute; left:680px; top:150px">
        <img src="../AldineLogo1.png" alt="Picture Cannot Be Viewed">
    </div>

    <div style="position:absolute; left:690px; top:350px"><button id="check" class="submit"  onclick="checkAnswer()">Submit Answer</button > </div>
    <div style="position:absolute; left:690px; top:405px"><button id="check2" class="previous"  onclick="previous()">Previous Question</button > </div>
  <div id="frame">
      <h3 id="question">Question here</h3>
            <div id="content" ></div>
            <div id="response"></div> 
  </div>
  <div id="score"><h3>Score: 0 right answers out of 0 possible</h3></div>
</div>
</body>
</html>

阿尔丁评估
变量测验=[
{
“问题”:“Q1:该学区的名称是什么?”,
“选择”:[“这是奥尔丁独立学区。”,
“这里是春季独立学区。”,
“这是克莱恩独立学区。”,
“这里是休斯顿独立学区。”],
“正确”:“这是奥尔丁独立学区。”,},
{
“问题”:“第2个问题:我们目前位于哪个城市?”,
“选择”:[“我们目前位于春天之城。”,
“我们目前位于休斯敦市。”,
“我们目前位于达拉斯市。”,
“我们目前位于圣安东尼奥市。”],
“正确”:“我们目前位于休斯顿市。”,},
{
“问题”:“问题3:我们目前所在的州是什么?”,
“选择”:[“我们目前位于德克萨斯州。”,
“我们目前位于路易斯安那州。”,
“我们目前位于亚特兰大州。”,
“我们目前位于佛罗里达州。”],
“正确”:“我们目前位于德克萨斯州。”,},
{   
“问题”:“第4季度:我们目前在哪个部门?”,
“选择”:[
“我们是金融服务部的一部分。”,
“我们是儿童营养部的一部分”,
“我们是技术服务部的一部分”,
“我们是儿童发展部的一部分”],
“正确”:“我们是技术服务部的一部分”,
{   
“问题”:“问题5:我们目前处于哪个月?”,
“选择”:[
“我们目前处于6月份”,
“我们目前处于7月份”,
“我们目前处于8月份”,
“我们目前处于9月份”
],
“正确”:“我们目前在6月份”,
];
var-currentQuestion=0;
var得分=0;
var askingQuestion=true;
var radioAnswer=新数组();
函数loadQuestion(){
//---------------设置用于创建单选按钮的临时变量-------------------------
无线电按钮;
//---------------清除上一个问题中的单选按钮----------------------------
document.getElementById('content').innerHTML=“”;
//---------------循环选择,并创建单选按钮----------------------------
for(var i=0;i';
}
}
函数previous(){
如果(当前问题