如何在录制正确和错误答案的同时在javascript中随机化测验?

时间:2017-06-06 05:02:40

标签: javascript

我正在尝试将测验循环5次,同时在返回开始菜单之前记录每个问题的正确答案,但我很难让它正常工作 任何帮助都将非常感激。

function cleartxt()
{
    setTimeout("document.getElementById('ans').innerHTML = ''", 3000);
}
var random = new Array(5);
var count = 0;
function next()
{
var store = 0;
do
{
store = (Math.round(Math.ceil(Math.random() * 40) -1));
}while(random.indexOf(store) > -1);
document.getElementById("ques").innerHTML = questions[store][0];
document.getElementById("rad1").innerHTML = questions[store][1];
document.getElementById("rad2").innerHTML = questions[store][2];
document.getElementById("rad3").innerHTML = questions[store][3];
document.getElementById("rad4").innerHTML = questions[store][4];
document.getElementById("image").src = images[store];
var radio = document.getElementsByName("rad");
while(store <= 5)
{   
    count++;
    if(store == 5)
        startMenu();
    if(radio[0].checked == true)
    {   
        if(questions[store][0] == questions[store][5])
            document.getElementById("ans").innerHTML = "Correct";
        else
            document.getElementById("ans").innerHTML = "Incorrect";
    }
    else if(radio[1].checked == true)
    {
        if(questions[store][1] == questions[store][5])
            document.getElementById("ans").innerHTML = "Correct";
        else 
            document.getElementById("ans").innerHTML = "Incorrect";
    }
    else if(radio[2].checked == true) 
    {
        if(questions[store][2] == questions[store][5])
            document.getElementById("ans").innerHTML = "Correct";
        else 
            document.getElementById("ans").innerHTML = "Incorrect";
    }
    else if(radio[3].checked == true)
    {
        if(questions[store][3] == questions[store][5])
            document.getElementById("ans").innerHTML = "Correct";
        else  
            document.getElementById("ans").innerHTML = "Incorrect";
    }
    else
        document.getElementById("ans").innerHTML = "Please select an answer!";
}
}
function startMenu()
{
    window.history.back();
}

0 个答案:

没有答案