hasOwnProperty method issue

Tell us what’s happening:
Describe your issue in detail here.

Hi there,

I am quite new to Javascript, I am meeting the hasOwnProperty method issue.
Please help me work on this.

Thanks.

  **Your code so far**

function checkObj(obj, checkProp) {
// Only change code below this line
const myObj = {
gift: "pony", 
pet: "kitten", 
bed: "sleigh",
city: "Seattle"
}

myObj.hasOwnProperty();

return checkObj;
// Only change code above this line
}
  **Your browser information:**

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

Challenge: Testing Objects for Properties

Link to the challenge:

This is the furthing solution I made which passed.


function checkObj(obj, checkProp) {
  // Only change code below this line
 if (obj.hasOwnProperty(checkProp)){
   return obj[checkProp];
 }
 else {
   return "Not Found";
 }
}

  const newObj = {
    gift: "pony", 
    pet: "kitten", 
    bed: "sleigh"
  };
  

  newObj.hasOwnProperty();

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

Hi @ArielJX !

Welcome to the forum!
I am glad you were able to pass the challenge but I do want to point out one important thing concerning your solution.

You don’t need to create an object at all.
You can delete all of this here

The reason why you shouldn’t create your own object is because you want to create a function that works for any object.
You should be able to use your function on hundreds of objects and not rely on having to write one out manually.

Hope that helps! :grinning:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.