Testing Objects for Properties in javascript

 function checkObj(obj, checkProp) {
  // Only change code below this line
  var obj = {
gift: "pony",
pet: "kitten",
bed: "sleigh",
city: "Seattle"
};
  if (obj.hasOwnProperty(checkProp)) {
    return obj[checkProp];
  } else {
    return "Not Found";
  }
  
}
// what is wrong with the code I am not getting.

Can you explain the purpose of this code?

Testing Objects for Properties

i am getting not found if run

I understand. Just to understand your current thinking of the problem, can you tell me the purpose of the above lines of code as it relates to solving the problem?

// running tests

checkObj({pet: "kitten", bed: "sleigh"}, "gift")

should return the string

Not Found

. // tests completed // console output Not Found Not Found

1 Like

if i do console.log(checkObj(“gift”));
i get Not Found

can you paste your full code please

1 Like
function checkObj(obj, checkProp) {

  // Only change code below this line

  var obj = {

gift: "pony",

pet: "kitten",

bed: "sleigh",

city: "Seattle"

};

  if(obj.hasOwnProperty(checkProp)) {

    return obj[checkProp];

  } else {

    return "Not Found";

  }

  

}

@vickynishad Can you please answer my last question?

i did answer you sir. look up.
i am getting an error in completing this challenge in freecodecamp javascript

you still have this in the code

var obj = {

gift: “pony”,

pet: “kitten”,

bed: “sleigh”,

city: “Seattle”

};

as Randell mentioned, what is the purpose of this ? The function has a parameter obj, and an argument gets passed to it

1 Like

or i have done something wrong in the code???

help me out if i did wrong coding. please sir

Please answer: Why did you put this in your code? What do you think that it does?

did you get my question ?

Testing Objects for Properties
in freecodecamp course javascript

Why did you add that portion of code? Please actually respond to what we are saying.

i am getting error in the code

Why did you add the six lines we are asking about? What do you think they do?