Basic JavaScript: Testing Objects for Properties - Code not working

Tell us what’s happening:
Hi everyone. My code doesn’t seem to return anything for if obj.hasOwnProperty is true, but works if it’s false. I tested it in firefox’s console and in VS Code, it works perfectly fine. Can anyone help me figure out what I’m missing?

Your code so far

function checkObj(obj, checkProp) {
// Only change code below this line
  var checker = obj.hasOwnProperty(checkProp);
  if (obj.hasOwnProperty(checkProp)) {
    return checkProp;
  else {
    return "Not Found";
return "Change Me!";
// Only change code above this line

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:75.0) Gecko/20100101 Firefox/75.0.

Challenge: Testing Objects for Properties

Link to the challenge:

Hello, one tip, you can use the var checker in the if statement, because the result will be the same as if you wrote obj.hasOwnProperty(checkProp) inside the if statement, but that’s up to you.
Going back to your question… Did you try deleting the return “change me”? Because that acts as an else, but you already defined the else statement right above, that might be the reason why your code is not passing. Let me know if that works :grinning:

1 Like

Lol thank you. That worked.

1 Like