5/6 SyntaxError: missing ) after condition


#1

Hey, this is my code. I get the alert that I've got a syntax error-SyntaxError: missing ) after condition. I've been over this over and over and I cant pick anything up. Please help?

var user = prompt("You've just arrived at prison, its your first day. Are you Scared or Fearless or Unsure").toUpperCase();
strong=true
fast=true
switch(user){
case 'FEARLESS':
if(strong && fast){
console.log("Congrats, you just rinsed the man, You're the man now!");
}

    else{
        console.log("You needed to be both strong and fast to win this fight");
    }
    break;

case 'SCARED':
    if(!fast){
        console.log("Its up to you and your wits now");
    }

    else{
        console.log("It looks like its flight time");
    }
    break;

case 'UNSURE':
    if(strong || (!fast){
        console.log("Looks like its just you and your muscles in this one");
        }

        else{
        console.log("You'd be smart to make up your mind quick");
    }
    break;

default:
console.log("You've just been knocked out");

};


#2

case 'UNSURE':
if(strong || (!fast){
console.log("Looks like its just you and your muscles in this one");
}

try taking out the first ( in your if statement around !fast. Let me know if this works.


#3

should be

 if(strong || (!fast) ) {

FEARLESS
=======================
  AND  | true  | false
 ------|-------|-------
 true  | true  | false
 ------|-------|-------
 false | false | false
 ------|-------|-------

SCARED
    =======================
       !   |
     ------|-------|
     slow  | true  | 
     ------|-------|

 UNSURE
 =======================
       | slow  | slow
  OR   | true  | false
 ------|-------|-------
 true  | true  | true
 ------|-------|-------
 false | true  | false
 ------|-------|-------

#4

Thanks for the help guys. @gaston1212 your solution did help.
The problem now is that it only runs either the if or else code for each scenario no matter what choice is made. For some reason once you choose a case, the outcome is set, no matter the following choice. My code does,t banch out, it just stays on a narrow path if that makes sense. Any thoughts?


#5

@devrockstar03761,

In the case's of your switch statement
your are accessing the =global= variables strong and fast

FEARLESS case
=======================
       | strong| strong
  AND  | true  | false
 ------|-------|-------
 fast  |       |
 true  | true  | false
 ------|-------|-------
 fast  |       |
 false | false | false
 ------|-------|-------

From the truth-Table you can make out

  • You will get the IF-code-block when fast and strong both have a Boolean Value of true

  • You will get the ELSE-code-block
    when =either= or =both= fast and strong have a Boolean Value of false

SCARED case
=======================
   !   |
 ------|-------|
 fast  |       |
 true  | false | 
 ------|-------|
 fast  |       |
 false | true  |
 - - - + - - - +

 UNSURE
 =======================
       | !fast | !fast
       | !false| !true
       |   |   |   |
       |   V   |   V
  OR   | true  | false
 ------|-------|-------
 strong|       |
 true  | true  | true
 ------|-------|-------
 strong|       |
 false | true  | false
 ------|-------|-------

To put this into words, would go beyond my paygrade.....