Javascript 重置进度条值jQuery

Javascript 重置进度条值jQuery,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我试图在测验结束后重置测验中的进度条 如果您遵循以下链接并: 回答问题 进度条根据问题的排列而上升 问答比赛结束 进度条保持在100% 这里有一个工作代码的链接 增加进度条的部分是 progress += questions.length * 100 / questions.length / questions.length; if ($('#progress').val() >= 100) { $('#progress').val(0); } $('#progr

我试图在测验结束后重置测验中的进度条

如果您遵循以下链接并:

  • 回答问题
  • 进度条根据问题的排列而上升
  • 问答比赛结束
  • 进度条保持在100%
  • 这里有一个工作代码的链接

    增加进度条的部分是

      progress += questions.length * 100 / questions.length / questions.length;
    
      if ($('#progress').val() >= 100) {
        $('#progress').val(0);
      }
      $('#progress').val(progress);
    
    但是,这只会增加,不会重置

    希望你能帮忙,这是代码

      var test_status, options, pos = 0,
      question, optA, optB, optC, option_radio, user_guess, correct = 0,
      progress = 0;
    
    var questions = [
      ['What is 4 * 4?', '16', '34', '18', 'A'],
      ['What is 80 / 20?', '49', '4', '3', 'B'],
      ['What is 760 - 160?', '650', '500', '600', 'C'],
      ['What is 330 + 150?', '480', '800', '400', 'A']
    ];
    // Function to get ids
    function _(x) {
      return document.getElementById(x);
    };
    // Function to ask the question
    function askQuestion() {
      // End of quiz
      if (pos >= questions.length) {
        test_status.innerHTML = 'Test Complete. You scored ' + correct + ' out of ' + questions.length;
        options.innerHTML = '<br>' + 'To attempt the quiz again' + '<br><br>' + '<button onclick = "askQuestion()"> Click here</button>';
        pos = 0;
        correct = 0;
        return false;
    
      }
    
      // Get position of question
      question = questions[pos][0];
      // Get positions of options
      optA = questions[pos][1];
      optB = questions[pos][2];
      optC = questions[pos][3];
      // Get test status id
      test_status = _('test_status');
      // Get options id
      options = _('options');
      // Print question stage
      test_status.innerHTML = "<h2> You are on question " + (pos + 1) + " out of " + questions.length + "</h2>";
      // Print current question
      options.innerHTML = "<h3>" + question + "</h3>";
      // Print options for Q
      options.innerHTML += "<input type ='radio' name ='options' value ='A'> " + optA + "<br>";
      options.innerHTML += "<input type ='radio' name ='options' value ='B'> " + optB + "<br>";
      options.innerHTML += "<input type ='radio' name ='options' value ='C'> " + optC + "<br><br>";
      // Add a submit button
      options.innerHTML += "<button onclick ='checkAnswer()'>submit</buton>";
    
    };
    // Check answer 
    function checkAnswer() {
    
      // Get name attr from raio 
      option_radio = document.getElementsByName('options');
      // loop through each radio
      for (var i = 0; i < option_radio.length; i++) {
        // check if option_radio is check
        if (option_radio[i].checked) {
          user_choice = option_radio[i].value;
        }
      }
      // check is correct
      if (user_choice == questions[pos][4]) {
        correct++;
        // increment progress based on questions length
      }
      pos++;
    
      progress += questions.length * 100 / questions.length / questions.length;
    
      if ($('#progress').val() >= 100) {
        $('#progress').val(0);
      }
      $('#progress').val(progress);
    
      askQuestion();
    
    };
    
    askQuestion();
    
    var测试\u状态,选项,位置=0,
    问题,optA,optB,optC,选项无线电,用户猜测,正确=0,
    进度=0;
    变量问题=[
    [4*4是什么?,'16','34','18','A'],
    [什么是80/20?,'49','4','3','B'],
    [“什么是760-160?”、“650”、“500”、“600”、“C”],
    [“330+150是什么?”、“480”、“800”、“400”、“A”]
    ];
    //获取ID的函数
    函数ux){
    返回文档.getElementById(x);
    };
    //提问的功能
    函数askQuestion(){
    //测验结束
    如果(位置>=问题长度){
    test_status.innerHTML='测试完成。您在'+问题.length'中获得'+正确+';
    options.innerHTML='
    '+'要再次尝试测验,'+'

    '+'单击此处'; pos=0; 正确=0; 返回false; } //获得问题的位置 问题=问题[pos][0]; //获取选项的位置 optA=问题[pos][1]; optB=问题[pos][2]; optC=问题[pos][3]; //获取测试状态id 测试状态=(测试状态); //获取选项id 选项=uu(“选项”); //打印问题阶段 test_status.innerHTML=“您在问题“+(pos+1)+”中的“+问题.length+”; //打印当前问题 options.innerHTML=“+问题+”; //Q的打印选项 options.innerHTML+=“+optA+”
    ”; options.innerHTML+=“”+optB+“
    ”; options.innerHTML+=“+optC+”

    ”; //添加提交按钮 options.innerHTML+=“提交”; }; //核对答案 函数checkAnswer(){ //从raio获取名称属性 option_radio=document.getElementsByName('options'); //在每台收音机中循环播放 对于(var i=0;i=100){ $('#progress').val(0); } $('进度').val(进度); askQuestion(); }; askQuestion();
    这是一个逻辑错误。只需在检查之前设置该值

      $('#progress').val(progress);
      if ($('#progress').val() >= 100) {
        $('#progress').val(0);
      }
    

    检查变量progress的值,而不是元素的值

     progress += questions.length * 100 / questions.length / questions.length;
    
      if (progress >= 100) {
        $('#progress').val(0);
      }
      $('#progress').val(progress);