In Switch case -what is valid?

// Tell us what’s happening:
//This passes the test in freeCodecamp course but I get an error for the case if I enter a //number. ie. switchOfStuff(3);

//Your code so far

function switchOfStuff(val) {
  var answer = "";
  // Only change code below this line
    case "a" || 1:
      return "apple";
    case "b" || 2:
      return "bird";
    case "c" || 3:
      return "cat";
    return "stuff";
  // Only change code above this line  
  return answer;  

// Change this value to test

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36.

Link to the challenge:

I’m not receiving an error message when I copy and paste the code into the editor.

I do think you’re confused about how the logical OR operator (||) works. case "a" || 1 doesn’t mean that either “a” or 1 satisfy the case.

MDN web docs

Logical OR ( || ) expr1 || expr2 If expr1 can be converted to true , returns expr1 ; else, returns expr2 .

The value of "a" || 1 will always be “a” according to how || works in JavaScript.

you can’t do this, if you want to match or a or 1 you need to do

case "a":
case 1:
   return "apple";

(you also don’t need break as the return statement exit from the function directly - if you do not have a return statement then you need break)

1 Like

Details. Thanks for clearing this up.