Something wrong with the syntax?


#1

var user = prompt("A thief runs into you, pulls out a knife and wants your wallet. Do you FIGHT, RUN or PAY him?").toLowerCase();
switch(user){
case 'fight':
var fight=prompt("Are you strong?");
var tech=prompt("Do you know how to disarm him?");
if (fight = 'yes' || tech = 'yes'){
console.log("You need atleast one. The thief wounded you and ran away with your wallet! Seek first aid!");
}else{
console.log("You succesfully disarm the thief and he runs away in fear! Good job!");
}
break;
case 'run':
var speed=prompt("Can you outrun him? Are you fast?");
var headstart=prompt("Can you get a headstart?");
if(speed='yes' || headstart='yes'){
console.log("You managed to run away. The thief stops following you because he doesn't want attention.");
}else{
console.log("The thief runs you down, wounds you and steals your wallet! Seek first aid!");
}
break;
case 'pay':
var money=prompt("Do you have more than 50$?");
var valuables=prompt("Do you have any valuables - jewelry, watch, something expensive?");
if (money='yes' || valuables='yes'){
console.log("You give the thief every valuable thing you have and he goes away.");
}else{
console.log("You don't have enough money to pay him. He wants your phone.");
var give=prompt("Do you give him your phone?");
if (give='yes'){
console.log("The thief runs away with your expensive smartphone");
}else{
console.log("The thief wounded you and ran away! Seek first aid!");
}
break;
default:
console.log("Please choose FIGHT, RUN or PAY!");
break;
}
It says "Invalid left-hand side of argument" but I can't see where is the problem. Please help.


#2

I cant see where the problem is since you need to organize your code... I cant tell you how important it is to carefully indent your code and make it organize, so if you have a problem i could easily identify it...


#3

Hi,
Change the = operator to == when it's necessary
exemple :

if (fight == 'yes' || tech == 'yes'){

#4

It's organized, but when I copy and paste it in the forum it loses the spaces and tabs, that's why it looks like this.
I changed the = to == . Now it says "there is a problem with your syntax"
Still, thanks for that.


#5

can you past all your code ? we can't help without that.
Don't forget to format it with the two tags [code ] [/code ] (without space to keep indentation)


#6

 var user = prompt("A thief runs into you, pulls out a knife and wants your wallet. Do you FIGHT, RUN or PAY him?").toLowerCase();
switch(user){
    case 'fight':
        var fight=prompt("Are you strong?");
        var tech=prompt("Do you know how to disarm him?");
        if (fight == 'yes' || tech == 'yes'){
            console.log("You need atleast one. The thief wounded you and ran away with your wallet! Seek first aid!");
        }else{
            console.log("You succesfully disarm the thief and he runs away in fear! Good job!");
        }
        break;
        case 'run':
            var speed = prompt("Can you outrun him? Are you fast?");
            var headstart = prompt("Can you get a headstart?");
            if(speed =='yes' || headstart =='yes'){
                console.log("You managed to run away. The thief stops following you because he doesn't want attention.");
            }else{
                console.log("The thief runs you down, wounds you and steals your wallet! Seek first aid!");
            }
            break;
            case 'pay':
                var money = prompt("Do you have more than 50$?");
                var valuables = prompt("Do you have any valuables - jewelry, watch, something expensive?");
                if (money =='yes' || valuables =='yes'){
                    console.log("You give the thief every valuable thing you have and he goes away.");
                }else{
                    console.log("You don't have enough money to pay him. He wants your phone.");
                    var give = prompt("Do you give him your phone?");
                    if (give =='yes'){
                        console.log("The thief runs away with your expensive smartphone");
                    }else{
                        console.log("The thief wounded you and ran away! Seek first aid!");
                    }
                    break;
                    default: 
                    console.log("Please choose FIGHT, RUN or PAY!");
                    break;
                }

#7

I saw my mistake, I hadn't completed the last 'else' statement with a }. It works now.