我的switch语句直接进入默认语句

时间:2013-06-24 03:22:58

标签: javascript switch-statement

   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??");

}

它从提示符直接转到默认值:,     我没有得到它我甚至有break;和东西。

1 个答案:

答案 0 :(得分: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??");

}