0

这是我的测验应用程序引擎,但我注意到我不能为一个问题分配多个答案而不会弄得一团糟。

answer[0] = ["Green", "Blue", "Red"]
answer[0] = "Green" or "Blue" "Red"

我开始研究多维数组,但我无法让它工作。请帮忙。这是我的引擎:

answer = new Array()
answer[0] = "Green"; //THIS IS LIMITED as there are more answers like red or blue
answer[1] = "2"; //Only one answer
question = new Array();
question[0] = "What colours are in the Rainbow";
question[1] = "1+1";
index = 0;

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



enter1.onRelease = function()
{
    if (answer_input.text == answer[index])
    {
        index++;
        answer_input.text = "";
    }
    else
    {
        answer_input.text = "Incorrect";
    }
};
4

1 回答 1

1
answer[0] = ["Green", "Blue", "Red"];

..那么条件应该是这样的:

enter1.onRelease = function(){

  var good=false;
  for(var i=0;i<answer[index].length;i++){
    if(answer[index][i]==answer_input.text){
      good=true;
    }
  }

  if(good){
    index++;
    answer_input.text = "";
  else{
    ...
  }
于 2013-01-31T13:12:49.753 回答