I was wondering if I can use switch statement instead of if / else. Any clues?

Any corrections to my “switch” statement?

function checkObj(obj, checkProp) {

switch (checkObj){
  case obj.hasOwnProperty:
    return obj[checkProp];
    break;
  default:
    return "Not Found";
    break;
}
}
  **Your browser information:**

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.53 Safari/537.36

Challenge: Testing Objects for Properties

Link to the challenge:

Generally you can’t. switch is used for matching a single input value against a series of case values. It’s done using strict equality.

switch (dogName) {
  case "Fido":
    // ...
    break;
  case "Snoopie"
    // ...
    break;
  default:
    // ...
    break;
}

is equivalent to

if (dogName === "Fido") {
  // ...
} else if (dogName === "Snoopie") {
  // ...
} else {
  // ...
}

But in your case, you’re attempting to match checkObj, which is a function, against obj.hasOwnProperty, which is a different function. It doesn’t really make sense.