Need some help


#1


if in the prompt box i pick the second option i get the default option. For example where i have || if i type almost good the result will be "please try again". Can someone tell me why it doesn t recognize the second answer from if statement and only the 1 st answer provided?

var user = prompt("how are you?").toLowerCase();

switch(user) {

case "good":

  if(user==="good"||user==="almost good") {
  console.log("very well then");
  } else {
      console.log("too  bad in this case");
  }

  break;


  case "not so good":

    if(user==="not so good" &&user==="almost not so good") {
  console.log("I hope u get better");
  } else {
      console.log("too  bad then");
  }
      break;


   case "bad":

       if(user==="bad" &&user==="almost bad") {
  console.log("very well then");
  } else {
      console.log("can t do much i guess");
  }
       break;
       default:
       console.log("please try again");

}


#2

The switch statement looks for "good", "not so good" and "bad". If you type almost good it won't recognise it as one of the options so it will execute the default.

If you really want to include both answers, you should add another case for "almost good".


#3

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