Lesson 5 mistakes


#1

Hi guys,

Here is my code:

var troll=prompt("you walk into a troll, do you fight him, pay or run?").toUpperCase();

switch(troll){
case"fight":

    var strong=prompt("are you strong?(YES or NO)").toUpperCase();

    var smart=prompt("are you smart?(YES or NO").toUpperCase();



    if(strong==="YES"&&smart==="YES"){

        console.log("you beat the troll")
    }
        else{console.log("the troll beats you");
        }
    break;



case"pay":

    var money=prompt("do you have money?(YES or NO)").toUpperCase();

    var food=prompt("do you have food?(YES or NO)").toUpperCase();

    if(money==="YES"||dollars==="YES"){
    console.log("you can go");
    }
        else{console.log("the troll eats you");
        }
    break;


case"run":
    var fast=prompt("are you fast?(YES or NO)").toUpperCase();
    var usainBolt=prompt("are you usain bolt?(YES or NO)").toUpperCase();
    if(fast==="YES"&&usainBolt==="YES"){
        console.log("you outrun the troll");}
        else{console.log("the troll eats you");}

    break;

default:
    console.log("I didnt understand you choice");

};

I'm guessing it's full of mistakes, can someone help me please?

Thanks a lot


#2

@ludosome,

You are using toUpperCase() and then in the =switch= you compare tolowercase

var troll=prompt(
    "you walk into a troll, "+
    "do you fight him, pay or run?").toLowerCase();

You are using a undeclared variable
dollars==="YES"