5. Logical Operators


#1

This is not so much a question of syntax, but what belongs where? I'm having trouble understanding what I'm supposed to be verifying with the operators. Don't I need more variables? You can see from the code comments where I am lacking information/understanding.

var user = prompt("Which path do you choose? Left, Right, Middle, Back, Forward are your options!").toLowerCase();

switch (user)
{
    case "left":
        console.log("You take the left path!");
        break;
        
    case "right":
        console.log("You take the right path!");
        break;
        
    case "middle":
        console.log("You take the middle path!");
        break;
        
    case "back":
        if(/* what goes here? */) {
        console.log("You want to go back?");    
        }
        else {
            console.log("Pick a direction!");
        }
        break;
        
    case "forward":
        if (/* what goes here? */) {
            console.log("You rush forward!");
        }
        else {
            console.log("Pick a way to go!");
        }
        break;
    
    default:
        console.log("Nope, choose again!");
        break;
    
}


#2

what you could do for example here:

case "back":
        if(/* what goes here? */) {
        console.log("You want to go back?");    
        }
        else {
            console.log("Pick a direction!");
        }
        break;

is add a another prompt:

moving_back = prompt("are you sure you want to move back? yes or no");

(which means the prompt should be before the if statement) then inside the if statement, check if moving_back is yes, which will show: "You want to go back?"

otherwise it will show, Pick a direction

You can do something similar for forward. Be creative, it is your game :slight_smile:


#3

OK, I think I understand now. I was afraid to expand more than exactly what it was telling me to add. I will add another prompt and then can use the operators. Thank you!


#4

but then there is nothing you can use your operators for, i think you can go pretty wild in this exercise (which doesn't go for every exercise). You can even add multiply prompts, and use || or && to make the story even better