2016-01-22 72 views
-2

我輸入文本字段有兩個可能的答案分別是「luah」或「滷」,但我的代碼是不工作:陣列從用戶和可能的答案進行比較的答案

stop(); 

//var jawapan1=Array; 

txt_zuhal.addEventListener(KeyboardEvent.KEY_DOWN,handler); 

function handler(event:KeyboardEvent) 
{ 
    //jawapan1=("luah", "hal"); 

    // if the key is ENTER 
    if(event.charCode == 13) 
    {  
     if(txt_zuhal.text == 'luah'||'hal') 
     {  
      trace("1.correct"); 
     } 
     else 
     { 
      trace("1.Sorry, Wrong answer"); 
     } 
    } 
} 
+1

你的if語句是不正確的語法,試試這個:'if(txt_zuhal.text =='luah'|| txt_zuhal.text =='hal')' –

回答

0
private function handler(event:KeyboardEvent):void 
    { 

     //jawapan1=("luah", "hal"); 

     // if the key is ENTER 

     if(event.charCode == 13) 
     { 
      if(txt_zuhal.text == "luah" || txt_zuhal.text == "hal") 
      {  
       trace("1.correct"); 
      } 
      else 
      { 
       trace("1.Sorry, Wrong answer"); 
      } 
     } 
    }