2013-06-24 72 views
1
var comics = prompt("hey do you like comic books? y or n").toUpperCase(); 
    switch(comics){ 
     case "do you like comics": 
      if(comics === "y" || comics === "yes" || comics === "Yes") { 
      prompt("Sweet!"); 
     }else{ 
      console.log("ummmm wrong answer"); 

     break; 
    } 


    var comics = prompt("so do you like batman or superman??").toUpperCase(); 
     case "sylk": 
     //So You Like Comics 
      if(answr === "superman" || answr === "Superman" && answr === "batman" || answr === "Batman"); 
      console.log("dude thats awesome me too!!"); 
      break; 
     default: 
      window.alert("uh can you re-type that??"); 

}我switch語句直行到默認聲明

它從提示直奔默認:, 我不明白,我甚至有break;的之類的東西。

+1

內的情況下,你不聲明'answr' 。此外,您的代碼不完整。請至少張貼整個開關盒。 – Raptor

+0

我雖然對'answr'聲明沒有關係。 @ShivanRaptor –

回答

5

你的語法是錯誤的

。在你的代碼中沒有switch,你需要通過用戶的選擇comics切換然後寫switch block

var comics = prompt("so do you like batman or superman??").toLowerCase(); 
switch(comics){ 
    case "sylk": 
     //So You Like Comics 
     if(answr === "yes" || answr === "Yes" || answr === "y") 
      console.log("dude thats awesome me too!!"); 
     break; 
    default: 
     window.alert("uh can you re-type that??"); 

} 
+0

感謝新程序員仍在努力學習好的寫作技巧。 @阿蘭P Johny –