Code functions. Need help figuring out why it runs through more options after it should end


#1

var user = prompt("You approach a wild Shersquatch through a gap in the woods. Have you been spotted? Answer YES or NO.").toUpperCase();
switch(user){
case 'YES':
var fightOrFlight = prompt("Do you choose to fight the elusive creature or just run away? Answer FIGHT or FLIGHT.").toUpperCase();
switch(fightOrFlight){
case 'FIGHT':
var braveChoice = prompt("Brave choice. The Shersquatch growls in rage. What is your weapon of choice? Answer SWORD, GUN, STICK, ROCK, or HANDS.").toUpperCase();
switch(braveChoice){
case 'SWORD':
console.log("You have severed the Shersquatch's head.");
break;
case 'GUN':
console.log("Pow! Right between the eyes.");
break;
case'STICK':
console.log("The Shersquatch snaps the stick along with your spine. You are dead.");
break;
case 'ROCK':
console.log("You throw the rock into the woods and the Shersquatch chases after it. You are able to escape alive.");
break;
case 'HANDS':
console.log("Using your super kung-fu abilities, you succeed defeating the Shersquatch once and for all.");
break;
default:
console.log("You cannot find a " + braveChoice + ", therefore the Shersquatch eats you alive.");
break;
}
case 'FLIGHT':
console.log("Bad choice. No one can outrun a Shersquatch. You are dismembered and made into a fine human stew.");
break;
default:
console.log("Any other choice results in your death and the death of any of your loved ones. THE END.");
break;
}
case 'NO':
var runFast = prompt("You turn and run as fast as you can back to where you came from. You look back to verify your safety. Is Shersquatch following? YES or NO.").toUpperCase();
switch(runFast){
case 'YES':
console.log("Shersquatch must have heard your carelessly loud footsteps. You will die a quick death.");
break;
case 'NO':
console.log("You have gone unnoticed. As long as you cherish your life leave these woods and never return for as long as you live.");
break;
default:
console.log("Because of your inability to follow instructions I have entered the game and killed you myself. GOODBYE!");
break;
}
default:
console.log("You must be blind or incompetent. You die!");
break;
}


#2

What is your error? :slightly_smiling:


#4

It usually shows the place to inspect.


#5

There isn't an error. It's just when I choose an option that ends in disaster it doesn't end the program. It logs the message and logs a prompt from a separate case instead of ending. If I choose stick it prompts from the runFast variable.


#6

You haven't nested them quite right if this is happening. Nest the errors inside the proper case.


#7

I think I figured it out. I seem to have forgotten to insert a break after a few cases.


#8

Thanks for the advice.


#9

You're welcome! :slightly_smiling: