[Solved] How to convert upper case to lowercase stored in a variable inside switch statment [duplicate]


The expression "cake" || "Cake" evaluates to true, because both those strings are truthy. So when user’s input is compared with that value, for example "cake" == true, it evaluates to true because the user’s input ("cake") is also truthy.

To ignore the case of user’s input, you can simply convert it to lowercase (by make.toLowerCase()) before comparing:

var make = prompt("Hey! What you are up to cake or pancake?");
switch (make.toLowerCase()) {
  case "cake":
    console.log("Okay! Great choice  We are working hard for your cake");
    break;
  case "pancake":
    console.log("Okay! Great choice   We are working hard for your pancake");
    break;
  default:
    console.log("Sorry we Only have cake or pancake to choose from.");
}

If you are not familiar with the concept of truthy or falsy values, you can read MDN’s documentation here: https://developer.mozilla.org/en-US/docs/Glossary/Truthy & https://developer.mozilla.org/en-US/docs/Glossary/falsy

1

solved How to convert upper case to lowercase stored in a variable inside switch statment [duplicate]