4. Switch (Whoops! Am a little conused.. :|)


#1


https://www.codecademy.com/courses/javascript-beginner-en-ZA2rb/0/4?curriculum_id=506324b3a7dffd00020bf661


My error message is like this:
SyntaxError: Invalid or unexpected token

(I know this is a lot of code, but i really need help to search. Is there a problem with my if's? Not too sure!)
Also, I might have done this in a weird and an unsufficient way, but it's my way :D

var user = prompt("You stroll through the forest. You meet on a horrible and ugly witch. What do you want to do? KILL her, RUN or PAY").toLowerCase();
switch(user) {
 case 'kill':
     var smart = prompt("Are you smart?").toLowerCase();
     var resistant = prompt("Are you resistant to potions?").toLowerCase();
     if(smart === "yes") {
      smart = true;   
     }
     else {
      smart = false;   
     };
     if(resistant === "yes") {
      resistant = true;   
     }
     else {
      resistant = false;   
     };
     if(smart || resistant) {
      console.log("You killed the witch! You are free to wander further down into the woods..");   
     }
     break;
     case 'run':
         var fast = prompt("Are you fast?").toLowerCase();
         var headstart = prompt("Do you get a headstart?").toLowerCase();
         if(fast === "yes") {
          fast = true;   
         }
         else {
          fast = false;   
         };
         if(headstart === "yes") {
          headstart = true;   
         }
         else {
          headstart = false;   
         };
         if(fast || headstart) {
          console.log("You run from the witch and survived.. How cowardish..");   
         }
         else {
          console.log("Oh no! The witch got you and poisoned you! RIP You..");   
         };
         break;
         case 'pay':
             var money = prompt("Do you have any money?").toLowerCase();
             var currency = prompt("Is the money in WCC (Witch currency)?");
             if(money === "yes") {
              money = true;   
             }
             else {
              money = false;   
             };
             if(currency === "true") {
              currency = true;   
             }
             else {
              currency = false;   
             };
             if(money || currency) {
              console.log("You paid the witch and you continued down the infinite woods..};
             }
             else {
              console.log("Oh, oh! You seem a little green in your face!");   
             };
             break;
     default:
     console.log("That's not any of the mentioned options!: KILL, RUN, PAY");
}


#2

I see an error before the semicolon.


#3

To me, it doesent say
console.log("You paid the witch and you continued down the infinite woods..};
It says:
console.log("You paid the witch and you continued down the infinite woods..");
But, anyways.. Thank you for taking your time.. :slightsmile: _


#4

Is that an extra curly bracket? I'm not sure, i'm probably making errors since i'm tired as ■■■■, but its at least worth looking at.


#5

Oh thanks! Now I see it! xD How could I have been so blind!?!? :expressionless:


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.