Javascript Object Properties

I am under simplifying this or what, what am I doing wrong here??


// Setup
var myObj = {
  gift: "pony",
  pet: "kitten",
  bed: "sleigh"
};

function checkObj(checkProp) {
  // Your Code Here
  
 checkProp.hasOwnProperty("gift"); {
  return "pony";
    
  } 
  
  checkProp.hasOwnProperty("pet"); {
  return "kitten";
    
  }
  
  
  checkProp.hasOwnProperty("house"); {
    return "Not Found";
  }
 
}

// Test your code by modifying these values
checkObj("house");

I’ve edited your post for readability. When you enter a code block into the forum, precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

markdown_Forums

There are a few things going wrong here.

When your function runs it first runs checkProp.hasOwnProperty("gift") which doesn’t actually do anything. Then it returns "pony". As soon as a return statement is hit, a function is done, so that’s all that happens. Your code just always returns "pony".

You are not using the object myObj at all. The point of this exercise is to get values from that object.

You are using .hasOwnProperty() on the argument variable checkProp. checkProp is just a string though, and does not have any properties. You are also not doing anything with the results of checkProp.hasOwnProperty(), so it’s just pointless code.

You are attempting to hardcode the answers to the test instead of writing a usable function.

I think you need to re-read the challenge instructions again a couple times.

so how does this example help me figure out a question with a function if there is no function within this example, just curios i will research elsewhere but wasn’t sure about this example.

var myObj = {
top: "hat",
bottom: "pants"
};
myObj.hasOwnProperty("top"); // true
myObj.hasOwnProperty("middle"); // false 

The method hasOwnProperty() works the same whether it is in a function or not.