Basic JavaScript: Testing Objects for Properties (Stuck On It)

Tell us what’s happening:

Got stuck on something. I am getting the following error messages when running the tests. Anyone see where the issue(s) is/are? thank you

// running tests

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

should return
"pony"

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

should return
"kitten"

checkObj({city: "Seattle"}, "city")
should return
"Seattle"
. // tests completed // console output

This is what I have so far:

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

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

// Only change code above this line
}
console.log(checkObj("city"));


**Your browser information:**

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

**Challenge:** Testing Objects for Properties

**Link to the challenge:**
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/testing-objects-for-properties

It looks like you’ve changed the signature of the function checkObj. From the instructions:

Modify the function checkObj to test if an object passed to the function ( obj ) contains a specific property ( checkProp ).

It should have two parameters, obj and checkProp, so the function declaration should look as follows:

function checkObj(obj, checkProp) {
  // your code here
}

If you want to continue debugging your code as you’re trying to now, then you should do something like this:

var myObj = {
  gift: "pony",
  pet: "kitten",
  bed: "sleigh",
  city: "Seattle"
};

console.log(checkObj(myObj, "city"));

Thank you. That was it!

// Only change code below this line

function checkObj(obj, prop) {

if (obj.hasOwnProperty(prop)) {

    return obj[prop];

} else {

    return "Not Found";

}

// Only change code above this line

} use this answer