Code your own adventure 2: Problem with switch loop


#1

https://www.codecademy.com/en/courses/javascript-beginner-en-ZA2rb/0/1?curriculum_id=506324b3a7dffd00020bf661

I have a feeling that i may just need to use a different method that i haven't learned yet but i've been trying to get this to run properly before i move on. I've tried to elaborate on the game. i have included notes where the misbehavior occurs.

there is a condition from the second switch statement that runs when it's not supposed to and even when both answers are no for the rest of the cases it returns the string which correlates to to the condition where 1 answer is yes and one answer is no. I'm sure i have overcomplicated this or just gone about it all wrong. i'm not expecting a solution just a shove in the right direction as i'm having no luck trying to figure it out on my own.

any help would be very much appreciated. also apologies for the political undertones. just trying to keep myself entertained.

Thanks


var user = prompt("Have you ever danced with the devil in the pale moonlight?").toUpperCase()
;
switch(user) {
    case 'YES':
        console.log("Let's see if you made a lasting impression!");
        break;
        
    case 'NO':
        console.log("There's a first time for everything");
        break;
        
    case 'TO WHICH DEVIL ARE YOU REFFERING?':
      var invite =  prompt("HAHAHA, I see you are well versed in the Dark Arts. Will you join us on our quest towards domination?(yes/no)").toUpperCase();
        switch(invite) {
            case 'YES':
                console.log("Sweet Darkness. Come, there is much work to do. And so little time. The dark lord has began inacting the , executive orders hahaa!"); 
                break;
                
            case'NO':
                console.log("The mysterious figure decapetates you and leaves your body slumped over itself in the sewers!");
                break;
            default :
            console.log("I don't have time for this shit!");
            }; 

        break;
        
        default:
        console.log("You will show respect to the dark lord");
};
if(user === "YES" || "NO") {
          var timeHasCome =  prompt("The Donald appears in a flurry of dead doves and very much live bats! He charges for you head on! Do you run, fight or  negotiate?").toUpperCase();
        }
          switch(timeHasCome) {
              case 'RUN':
                  var answer1 = prompt("Are you fast?(yes/no)").toUpperCase();
          }
                  if (answer1 === "YES" || "NO") {
                    var answer2 =  prompt("Did you get a head start?(yes/no)");
                  } /* var answer2 runs even when the case is 'FIGHT' or 'NEGOTIATE'*/
                    if (answer1 && answer2 ==="YES") {
                        console.log("You got away clean!");
                    }
                        else if (answer1 || answer2 == "NO") {
                            console.log("You got away but only just!");
                        }  /*returns even when both answers are no*/
                        else if (answer1 && answer2 === "NO") {
                            console.log("The Donald eats your brains!");
                        };
                    
          /* had to redefine the switch statement here as trying to run 'FIGHT' as a case in the same switch returns an "illegal break statement" error have a feeling this may be where the main problem stems*/  switch(timeHasCome) {
                        
                case 'FIGHT':
                  var answer1 = prompt("Are you strong?(yes/no)").toUpperCase();
          
                  if (answer1 === "YES" || "NO") {
                    var answer2 =  prompt("Are you smart?(yes/no)");
                  }
                    if (answer1 && answer2 ==="YES") {
                        console.log("You tear the Donald to pieces, starting with the most unusual piece of all. his hair piece. you scalp him and force feed the top of his tangerine skull to the mysterious figure!!");
                    }
                        else if (answer1 || answer2 == "NO") {
                            console.log("After a short struglle, you get lucky and strike the Donald a deadly blow to the head!");
                        } /* This line is returned even when both answers === NO*/
                        else if (answer1 && answer2 === "NO") {
                            console.log("The Donald eats your brains!");
                        }
                        break;
                        
                        case 'NEGOTIATE':
                  var answer1 = prompt("Are you smart?(yes/no)").toUpperCase();
          
                  if (answer1 === "YES" || "NO") {
                    var answer2 =  prompt("Are you likeable?(yes/no)").toUpperCase();
                  }
                    if (answer1 && answer2 ==="YES") {
                        console.log("You convince the donald that his actions are akin to those of the most vile and disgusting human beings that have ever walked this earth. He falls at your feet and begs for mercy and forgivness. you have just saved the world!");
                    }
                        else if (answer1 || answer2 == "NO") {
                            console.log("After a short debate, you get lucky and the Donald is killed by a refugee who jumped from a plane rather that return to a certain death in their homw country! The Donald broke her fall. she lives out her life happy and free!"); /* This line is returned even when both answers === NO. i think this recurring problem is for the same reason that the "did you get a head start" string runs from line 39 when it's not supposed to*/
                        }
                        else if (answer1 && answer2 === "NO") {
                            console.log("The Donald eats your brains!");
                        }
                        break;
                        
                        default:
                        console.log("Well that wasn't much use was it!");
                        };


#2

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