0

这些问题是随机的,但它们显示了我的需要。正如您在 answer[0] 中看到的那样,我必须指定三个可能的答案。如果“bill”写在他们答案的任何地方,我希望能够说明答案是正确的。但这行不通

for (var i = 0; i < answer[index].length; i++)
{
    for (answer[index][i] in answer_input.text.toLowerCase())
    {
        correct = true;

    }


answer = new Array();
answer[0] =  ["your name is bill","bill's your name","your name's bill"]
answer[1] = ["john", "sean", "greg"]
question = new Array();
question[0] = "whats my name?"
question[1] = "whats not my name?"
index = 0;

onEnterFrame = function ()
{
    question_txt.text = question[index];
};

enter1.onRelease = function()
{
    question_txt.text = question[index];
    var correct = false;
    for (var i = 0; i < answer[index].length; i++)
    {
        if (answer[index][i] == answer_input.text.toLowerCase())
        {
            correct = true;

        }
    }

    if (correct)
    {
        index++;
        answer_input.text = "";
    }
    else
    {
        answer_input.text = "Incorrect";
    }
};
4

1 回答 1

0

如果您只想检查答案中是否写有“bill”,为什么不使用

answer_input.text.toLowerCase().indexOf( "bill", 0 )

如果“bill”在那里,该函数将返回它在答案中出现的索引。如果不存在,将返回 -1。

于 2013-02-05T15:25:53.280 回答