如何在测验中输入问题的Excel数据库?

时间:2019-05-07 09:25:12

标签: javascript html

我正在创建一个基于数学的测验,我想在其中添加一个已创建的乘法问题的excel数据库,并将其插入我的代码中,该代码将随机生成问题,并允许您输入答案而不是多项选择。

我已经将我的测验变成了多项选择测验,而没有添加问题,并且尝试查看在线教程以获取某种指导,以查看是否有解决方案,但是它并没有帮助,我有困难。

<!DOCTYPE html>
    <head>
    <title>Random Quiz</title>
    <style>
     div#test{ border:#000 1px solid; padding:10px 40px 40px 40px; }
    </style>
    </head>
    <body>
    <div>
     <h2 id="test_status">Math Quiz</h2>
     <h3 id="timeleft">Time left</h3>
    </div>
    <div id="test"></div>

    <script>
    var myVar;
    function startTimer() {
      myVar = setInterval(function(){myTimer()},1000);
      timelimit = maxtimelimit;
    }
    function myTimer() {
      if (timelimit > 0) {
        curmin=Math.floor(timelimit/60);
        cursec=timelimit%60;
        if (curmin!=0) { curtime=curmin+" minutes and "+cursec+" seconds left"; }
                  else { curtime=cursec+" seconds left"; }
        $_('timeleft').innerHTML = curtime;
      } else {
        $_('timeleft').innerHTML = timelimit+' - Out of Time - no credit given for answer';
        clearInterval(myVar);
      }
      timelimit--;
    }


    var pos = 0, posn, choice, correct = 0, rscore = 0;
    var maxtimelimit = 20, timelimit = maxtimelimit;  // 20 seconds per question

    var questions = [

    ];
    var questionOrder = [];
    function setQuestionOrder() {
      questionOrder.length = 0;
      for (var i=0; i<questions.length; i++) { questionOrder.push(i); }
      questionOrder.sort(randOrd);   // alert(questionOrder);  // shuffle display order
      pos = 0;  posn = questionOrder[pos];
    }

    function $_(IDS) { return document.getElementById(IDS); }
    function randOrd() { return (Math.round(Math.random())-0.5); }
    function renderResults(){
      var test = $_("test");
      test.innerHTML = "<h2>You got "+correct+" of "+questions.length+" questions correct</h2>";
      $_("test_status").innerHTML = "Test Completed";
      $_('timeleft').innerHTML = '';
      test.innerHTML += '<button onclick="location.reload()">Re-test</a> ';
      setQuestionOrder();
      correct = 0;
      clearInterval(myVar);
      return false;
    }
    function renderQuestion() {
      var test = $_("test");
      $_("test_status").innerHTML = "Question "+(pos+1)+" of "+questions.length;
      if (rscore != 0) { $_("test_status").innerHTML += '<br>Currently: '+(correct/rscore*100).toFixed(0)+'% correct'; }
      var question = questions[posn][0];
      var chA = questions[posn][1];
      var chB = questions[posn][2];
      var chC = questions[posn][3];
      test.innerHTML = "<h3>"+question+"</h3>";
      test.innerHTML += "<label><input type='radio' name='choices' value='A'> "+chA+"</label><br>";
      test.innerHTML += "<label><input type='radio' name='choices' value='B'> "+chB+"</label><br>";
      test.innerHTML += "<label><input type='radio' name='choices' value='C'> "+chC+"</label><br><br>";
      test.innerHTML += "<button onclick='checkAnswer()'>Submit Answer</button>";
      timelimit = maxtimelimit;
      clearInterval(myVar);
      startTimer();c
    }

    function checkAnswer(){
      var choices = document.getElementsByName("choices");
      for (var i=0; i<choices.length; i++) {
        if (choices[i].checked) { choice = choices[i].value; }
      }
      rscore++;
      if (choice == questions[posn][4] && timelimit > 0) { correct++; }
      pos++;  posn = questionOrder[pos];
      if (pos < questions.length) { renderQuestion(); } else { renderResults(); }
    }

    window.onload = function() {
      setQuestionOrder();
      renderQuestion();
    }
    </script>

    </body>
    </html>

我希望该测验从我的数据库中生成随机问题,并允许用户手动输入答案,而不是使其成为多项选择测验并手动键入所有乘法问题。

0 个答案:

没有答案