5, code your own adventure 2! How can I make this work?


#1

This question is a bit confusing. The instructions are:
Add some if/else statements to your cases that check to see whether one condition and another condition are true, as well as whether one condition or another condition are true. Use && and || at least one time each.
However, I wanted to add a few more things in. How could i make this work with && / || statements? This is my code:

var user = prompt("Welcome to the mystery doors.Gorkpog is coming to destroy all your sandwich bags. You must retrieve a weapon to destroy him with, but to make it more interesting. I have hid the weapon behind 1 of 3 doors. You must choose carefully are you ready? Which door do you choose, Door 1, Door 2, or Door 3?").toUpperCase(); 

switch(user) {
    case 'door1':
    console.log("Your weapon is: A Bowl of noodles");
    break;
    case 'door2':
    console.log("Your weapon is: An electric katana!");
    break;
    case 'door3':
    console.log("Your weapon is: Leather socks");
    break;
    default:
    console.log("Choose a door");
    break;
    
}
switch(user) {

if (userAnswer === door1) {
    console.log("You couragesly hold up your bowl of noodles. Gorkpog swallows you and wears the bowl of noodles as a hat.");
} 
else if {
    (userAnswer === door2) {
    console.log("Gorkpog see's your katana and charges at you instantly. You jump off the wall and aim your sword at Gorkpog. Gorkog aborbs the electricutes from your katana and electricutes you");
} else if {
    (userAnswer === door3) {
        console.log("Gorkpog screams 'YASSSSS' and hapily accepts your gift. Sandwich bags still intact");

    }else{
        console.log("Your sandwich bags are destroyed by Gorkpog");
    }
break;   
}

Thanks!


#2

switch(user) {
    case 'door1':
    console.log("Your weapon is: A Bowl of noodles");
    break;
    case 'door2':
    console.log("Your weapon is: An electric katana!");
    break;
    case 'door3':
    console.log("Your weapon is: Leather socks");
    break;
    default:
    console.log("Choose a door");
    break;
    
}

That is how a switch works. The second switch therefore won't work. What you need to do now is to add a condition in one of your cases e.g.

case 'door3':
    console.log("Your weapon is: Leather socks");
    if(condition&& condition){...}
    else if(condition || condition{...}
    else{...};
    break;
default: ...

Now you need to fill the blanks with something that suits your purpose.


#3

Thanks. New question not when i try running this part I get a syntax error for else. I tried adding another open curly brace before else but that did't work. What should I do?

....case 'door3':
console.log("Your weapon is: Leather socks");
break;
if( userAnswer === door1 && 8===8){
console.log("You couragesly hold up your bowl of noodles. Gorkpog swallows you and wears the bowl of noodles as a hat.");
}
else if (userAnswer === door2 || 4===2) {
console.log("Gorkpog see's your katana and charges at you instantly. You jump off the wall and aim your sword at Gorkpog. Gorkog aborbs the electricutes from your katana and electricutes you");
}
}else if (userAnswer=== door3 || 2+5=1) {
console.log("Gorkpog screams 'YASSSSS' and hapily accepts your gift. Sandwich bags still intact");
}
else {
console.log("Your sandwich bags are destroyed by Gorkpog");

default:
console.log("Choose a door");
break;

}


#4

it doesn't make much sense to break here:

....case 'door3':
    console.log("Your weapon is: Leather socks");
    break;

when the next case starts much later. And you else seems to lack a }.