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.

Testing Objects for Properties

i am getting not found if run

// 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";

  }

  

}

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?

there is an issue with your code. The easiest way to explain the issue would be if you explain why you have written the code in the way you did, particularly this part below


  var obj = {

gift: "pony",

pet: "kitten",

bed: "sleigh",

city: "Seattle"

};

1 Like

i am beginner sir. i am having this issue the help me out about this

if there is something wrong then would you make me understand i am beginner in coding