Is there an "everything" variable?


#1

Is there an everything variable? While creating my switch statement for 4/6 "Code Your Own Adventure", I made an option in which I wanted whatever the user answer is to be valid. I want to make a code where when the user answers the question "What food do you have?" anything will be acceptable.

var user = prompt("You are crossing a dangerous and unstable bridge.
 A giant bird suddenly lands on it and the bridge shakes violently. 
It asks you if you have any food. Do you answer it, try to shoo it
 away, or ignore it and run across the bridge?").toLowerCase();

switch(user)
case 'answer it':
    
    var answer = prompt("Do you say yes or no?").toLowerCase();
    if (answer === 'yes') {
      var food =  prompt("What food do you have?")
    }
    else
    {
        alert("You do not have any food for the bird so it eats you instead.");
    };
    
    break;
    
    case 'try to shoo it away' :
        var shoo = prompt("Do you ask it politely or try to hit the bird").

#2

@dragonflare,
Please read
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/switch
and you will konw that you will have to encapsulate your case's
in a pair of curly-brackets-{ }
like

user="answer it"
switch(user) {
  case 'answer it':
    var answer = prompt("Do you say yes or no?").toLowerCase();
    if (answer === 'yes') {
      var food =  prompt("What food do you have?")
    }
    else    {
        alert(
          "You do not have any food for the bird "+
          "so it eats you instead.");
    }
    break;
    
  case 'try to shoo it away' :
        var shoo = prompt(
          "Do you ask it politely or try to hit the bird")
        break;
  default:
        console.log("Don't know !!");
 }

#3

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