JavaScript将随机数组对象与另一个数组进行比较

时间:2013-11-16 15:13:48

标签: javascript arrays object for-loop compare

我正在使用JavaScript进行移动应用程序,以便使用数组进行分配

我从1个阵列中得到5个随机问题,并在点击按钮时显示它们

var showQuestions = new Array(5);
var questions = new Array(8);
var answers = new Array(8);

questions[0] = "What is the first planet";
questions[1] = "What is the second planet";
questions[2] = "What is the third planet";
questions[3] = "What is the fourth planet";
questions[4] = "What is the fifth planet";
questions[5] = "What is the sixth planet";
questions[6] = "What is the seventh planet";
questions[7] = "What is the eighth planet";

answers[0] = "Mercury";
answers[1] = "Venus";
answers[2] = "Earth";
answers[3] = "Mars";
answers[4] = "Jupiter";
answers[5] = "Saturn";
answers[6] = "Uranus";
answers[7] = "Neptune";

function generateQs()
{
    for(var i = 0 ; i < showQuestions.length ; i++)
    {
        var rand = Math.floor(Math.random() * questions.length);
        showQuestions[i] = questions[rand]
    }
    window.location = "#page2";
}

function showQ()
{
    clean = "";

    for(var j = 0 ; j < showQuestions.length ; j++)
    {
        document.getElementById('goHere').innerHTML = clean;
        document.getElementById('goHere').innerHTML = showQuestions[0]
    }
}

我需要做的是能够将问题与相应答案的答案进行比较。 任何帮助将不胜感激。

0 个答案:

没有答案