Code is showing "Unexpected token else"


#1

Below is my code, please help where am I wrong:

var user = prompt("Make a choice. Hit, Pay or Run").toUpperCase();

switch (user){
    case 'Hit':
        var punch = prompt("blow on face? Yes or No");
        var kick = prompt("Give him a kick? Yes or No");
       if (punch === 'Yes' && kick === 'Yes') {
           console.log("Good Choice, You Win!");
           else {
               console.log("He's strong. You lose");
           }
           break;
  case 'Pay':
      var cash = prompt("Give him all your cash? Yes or No);
      var cheque = prompt("Write him a cheque? Yes or No);
      if (cash === 'Yes' && cheque === 'No'){
          console.log("Good Choice, You are safe!");
      }
    else {
        console.log("Dumb choice, You lose");
    }
    break;
    case 'Run':
        var run = prompt("Run as fast as you can. Yes or No");
        var hide = prompt("Dont run, but hide. Yes or No");
        if (run === 'Yes' || hide === 'Yes'){
            console.log("Good Choice, you are safe!");
        }
        else {
            console.log("You are stuck. You lose");
        }
        break;
  default:
    console.log("I didn't understand your choice. select Hit, Pay or Run");
};

#2

Your error is on this line, check your opening and closing brackets and see if you can figure out where the error is here.


#3

corrected it: now error is unexpected token ILLEGAL

var user = prompt("Make a choice. Hit, Pay or Run").toUpperCase();

switch (user){
    case 'Hit':
        var punch = prompt("blow on face? Yes or No");
        var kick = prompt("Give him a kick? Yes or No");
       if (punch === 'Yes' && kick === 'Yes') {
           console.log("Good Choice, You Win!");
           } else {
               console.log("He's strong. You lose");
           }
           break;

#4

Can you see what's wrong in this line of code?

Also, you have the variable "user" ".toUpperCase()" Which means it will be all in caps, "LIKE THIS" What does this mean? It means that it will never say "Hit", "Pay", or "Run". Instead it will say "HIT", "PAY", "RUN". What does this mean for you? It means your case statements will ALWAYS be wrong, and revert to your default case saying "I didn't understand your choice. select Hit, Pay or Run".


#5

It worked. Thanks a ton!

var user = prompt("Make a choice. Hit, Pay or Run").toUpperCase();

switch (user){
case 'HIT':
var punch = prompt("blow on face? Yes or No");
var kick = prompt("Give him a kick? Yes or No");
if (punch === 'Yes' && kick === 'Yes') {
console.log("Good Choice, You Win!");
} else {
console.log("He's strong. You lose");
}
break;
case 'PAY':
var cash = prompt("Give him all your cash? Yes or No");
var cheque = prompt("Write him a cheque? Yes or No");
if (cash === 'Yes' && cheque === 'No'){
console.log("Good Choice, You are safe!");
} else {
console.log("Dumb choice, You lose");
}
break;
case 'RUN':
var run = prompt("Run as fast as you can. Yes or No");
var hide = prompt("Dont run, but hide. Yes or No");
if (run === 'Yes' || hide === 'Yes'){
console.log("Good Choice, you are safe!");
} else {
console.log("You are stuck. You lose");
}
break;
default:
console.log("I didn't understand your choice. select Hit, Pay or Run");
}