Need Help Debugging 4.Switch


#1


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

I have three current issues.

  1. When I am prompted to RUN or INVESTIGATE the computer returns 'Scaredy cat. Game over' for either choice I make and I also receive a Error stating I need to make sure to use a break statement for each case.

  2. I get the same Error message after I choose KEEP WALKING. Although I am getting the correct return from the computer.

  3. When I try and choose a friend. No matter what combination I make it I get a Error saying 'whoWillItBe' is undefined

    var user = prompt("You are outside of the abandoned insane asylum on Halloween night. Do you GO IN, KEEP WALKING, or FIND A FRIEND?").toUpperCase();
    switch(user) {
        case 'GO IN':
        var fightFlight = prompt("You're brave. As you walk into the building you hear a door shut down the hallway. Turn and RUN or go INVESTIGATE?").toUpperCase();
            if ("RUN") {console.log("Scaredy cat! Game over!");}
            else {console.log("Ok. Here we go...");}
        break;
        case 'KEEP WALKING':
            console.log("Back to mommmies house we go");
        break;
        case 'FIND A FRIEND':
            var whoWillItBE = prompt("JOHNNY is the strongest, SALLY is the smartest, BOBBY has all the candy. Who will you take with you?").toUpperCase(); 
            switch(whoWillItBe) {
            case 'JOHNNY && SALLY && BOBBY':
                console.log("Bring the whole squad. Good idea.");
                break;
            case 'JOHNNY && BOBBY !SALLY':
                console.log("Strength and Snickers. That's all you                                                         need");
                break;
            case 'JOHNNY && SALLY !BOBBY':
                console.log("You're leaving the candy behind! You                                                         crazy");
                break;
            case 'SALLY && BOBBY !JOHNNY':
                console.log("Smarts and Snickers. That's all you                                                       need");
                break;
            case 'SALLY':
                console.log("All you need is a brain");
                break;
            case 'BOBBY':
                console.log("You little fatty");
                break;
            case 'JOHNNY':
                console.log("Of course you pick the strongest");
            default:
                console.log("Please pick a valid friend");
            }
            default:
            console.log("Please make a valid selection");
    };

#2

HI first this part

if ("RUN")

you should make a comparison between fightFlight and "RUN" inside the if condition

if (condition) {

}
else {

}

and this case it's missing the break

case 'FIND A FRIEND':
   #here go your code

break;
default:
    ...

then inside the case... case 'FIND A FRIEND': its also missing the break to

case 'JOHNNY':
    #here your code
break;

#3

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