2014-12-02 109 views
0

我看不出有什么我做错了意外的令牌的情况下switch语句

var user = prompt ("You are minding you own bissueness when a man in a big white van pulls up? What do you do run, pop a cap in his *error 343*, or hop in?").toLowerCase(); 
switch (user) 
    case 'run': 
     var headstart = propmt ("Let's hit it. Did you run track or Cross Country this year? Yes or no?").toLowerCase(); 
     var fast = prompt ("Are you fast? Yes or No?").toLowerCase(); 
     if (headstart === 'yes' || fast === 'yes') 
     { 
      console.log("You live to cruze another day?"); 
     } 
     else 
     { 
      console.log("Sorry... you were taken and sold in to Mexico"); 
     } 
     break; 
    case 'pop a cap in his *error 343*': 
     var gun = prompt(" Ok, we went with gun. Do you have a gun on you? Yes or No").toLowerCase() 
     var loaded = prompt("Is you gun loaded? Yes or No?").toLowerCase() 
     if (gun === 'yes' && loaded === 'yes') 
     { 
      console.log("There were no witnesses, you get away clean!"); 
     } 
     break; 
    case 'hop in': 
     console.log("He turned out to be a nice man and lets you work in Mexico for free forever!") 
     break; 
     default: 
     console.log("I didn't understand your choice."); 
     } 

回答

-1

一切后开关需要的花括号内。今天早些时候我有同样的问题。

您有:

switch(x) 
    case 1: 
     //statement 
     break; 
    case 2: 
     //statement 
     break; 

你应该有什么:

switch(x) 
    {    //You were missing this bracket 
     case 1: 
      //statement 
      break; 
     case 2: 
      //statement 
      break; 
    }    //You were also missing this bracket