Code your Own Adventure


#1

How come this always comes out as you need weapons!!! The dragon got you..." when you choose to Fight him???

var answer = prompt("You meet a ferocious dragon, what are you gonna do? Fight him, Run away, Trick him, Fake your death, or pay him?").toUpperCase();
var user = answer;
switch(user){
case 'FIGHT HIM':
prompt("Are you good at fighting?, and do you have a sword and shield?").toUpperCase();
if(prompt === "yes, no" || "yes no" || "yes and no"){
console.log("you need weapons!!! The dragon got you...");
} else if(prompt === "no, yes" || "no yes" || "no and yes"){
console.log("you have to learn how to fight, otherwise you're dead..." );
} else if(prompt ==="yes, yes"||"yes yes"||"yes and yes"||"yes for both"){ console.log("the dragon ran away screaming in anger; YOU WON!!!");
} else{
console.log("you don't have anything?, you just go maimed.");
}
break;
case 'RUN AWAY':
console.log("Sad to tell you, but the dragon can fly really fast, so game over!");
break;
case 'TRICK HIM':
prompt("Are you smart?");
break;
case 'FAKE YOUR DEATH':
console.log("Your Lucky!!! The dragon wasn't hungry today, so you just escaped with your limbs intact!");
break;
case 'PAY HIM':
prompt("What form of money is the money you're giving to the dragon?");
break;
default:
console.log("You're so scared you can't even move? To bad, GG for life!!");
};


#2

Hi @codeplayer66523,

Please see the code example below. In short the use of your toUpperCase() method and your evaluation of expressions in the if statements are causing your issue, go ahead and make the adjustments you need and you should be good to kick some dragon butt, or be toasted :wink:

var answer = prompt("You meet a ferocious dragon, what are you gonna do? Fight him, Run away, Trick him, Fake your death, or pay him?").toUpperCase();
var user = answer;
switch(user){
    case 'FIGHT HIM':
    prompt("Are you good at fighting?, and do you have a sword and shield?").toUpperCase();
    if(prompt === "YES, NO" || prompt === "YES NO" || prompt === "YES AND NO") { //when evaluating expressions always do the whole expression. Also note above you use toUpperCase() but here you compare lower case
        console.log("you need weapons!!! The dragon got you...");
    } 
    else if (prompt === "no, yes" || "no yes" || "no and yes"){ //same here upper vs lower and expression evaluation
        console.log("you have to learn how to fight, otherwise you're dead..." );
    } 
    else if(prompt ==="yes, yes"||"yes yes"||"yes and yes"||"yes for both"){ 
        console.log("the dragon ran away screaming in anger; YOU WON!!!");
    } 
    else{
        console.log("you don't have anything?, you just go maimed.");
    }
    break;
    
    case 'RUN AWAY':
    console.log("Sad to tell you, but the dragon can fly really fast, so game over!");
    break;
    
    case 'TRICK HIM':
    prompt("Are you smart?");
    break;
    
    case 'FAKE YOUR DEATH':
    console.log("Your Lucky!!! The dragon wasn't hungry today, so you just escaped with your limbs intact!");
    break;
    
    case 'PAY HIM':
    prompt("What form of money is the money you're giving to the dragon?");
    break;
    
    default:
    console.log("You're so scared you can't even move? To bad, GG for life!!");
};

#3

Thx!!!! Your advice really helped!!! now it works