Logical operators syntax error


#1


When I run the code I receiving the error message 'SyntaxError: missing ) after argument list.' I just can't seem to find this error.


var user = prompt("You feeling lucky, punk?").toUpperCase();

switch(user) {
    case 'YES':
        console.log("Bring it on!");
        var fight = prompt("You wanna fight this crazy bastard?");
        if(fight && user) {
            console.log("Forget the gloves, this is bareknuckle!");
        } else {
            console.log("Woah! we better get out of here!");
        }
        break;
    case 'NO':
        console.log("HAHAHAHAHAHAHA!");
        var run = prompt("This guy must be drunk! You wanna get out of here?");
        if(run || user) {
            console.log("Luck escape!");
        } else {
            console.log("Perhaps we should get some help!");
        }
        break;
    case 'MAYBE':
        console.log("Well let's find out!");
        var dice = prompt("Looks like he wants you to roll some dice. Are you gonna play?")
        var play = Math.floor(Math.random()11 + 1)
        if (!dice) {
            console.log("Quick, Run!");
        } else if (play >= 6) {
            console.log("Looks let he'll let us leave.");
        } else {
            console.log("Holy Crap! He's coming right at us!");
        }
        break;
    default:
    console.log("It was a YES, NO or MAYBE question!");
};


#2

here is your problem:

var play = Math.floor(Math.random()11 + 1)

And please can you explain me what you wanna try here:

 if(fight && user) 
{
            console.log("Forget the gloves, this is bareknuckle!");
} 
else 
{
            console.log("Woah! we better get out of here!");
}

#3

Yep you are 100% right :stuck_out_tongue_winking_eye:


#4

I'm trying to say of both var user and var fight are true it should console.log "forget the gloves..." other wise it should console.log "Woah..."


#5

Okay and you know that we only get in the else case, if we didnt type anything in the prompt

var fight = prompt("You wanna fight this crazy bastard?");

and clicking on the "Ok" button ???

I only ask you cause i think you missunderstood this

if(fight && user)

#6

Yes I see what you mean, but I am unsure on how to force an input to the prompt? Perhaps an else if statement after the initial if statement?


#7

I think you wanna give a other feedback if the user types fight == yes and user == No

if(fight == "YES" && user == "YES")

This should work, please try it out


#8

Yes this now works. Thank you very much for your time, you really helped!


#9

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