2014-12-02 76 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