Basic JavaScript - Testing Objects for Properties

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

  **Your code so far**
function checkObj(obj, checkProp) {
// Only change code below this line
return "Change Me!";
// Only change code above this line
}
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36

Challenge: Basic JavaScript - Testing Objects for Properties

Link to the challenge:

Welcome to the forum!
What issues do you have with this task?

Adam There is a Problem with the challenge I think.
Check this:

  • checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "gift") should return the string pony.

  • Passed:checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "pet") should return the string kitten.

  • Passed:checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "house") should return the string Not Found.

  • Passed:checkObj({city: "Seattle"}, "city") should return the string Seattle.

  • Passed:checkObj({city: "Seattle"}, "district") should return the string Not Found.

  • Failed:checkObj({pet: "kitten", bed: "sleigh"}, "gift") should return the string Not Found.

on the very first pass you see “gift” should return “pony”.
and on the last failed why do I see “gift” should return Not Found

Different objects are passed into the function on different tests.

Would you mind can you please provide me the solution.

We aren’t allowed to write solutions for users.

You need to use the obj passed into the function.

See Than:

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

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

You need to delete this

if I delete this how does the code works without object items

The object is a function argument

than once we initialize it. its Automatically became Global
and if I need to delete this how can I pass all without initializing it inside the function either In the comments

You don’t put the object anywhere. The values of the arguments are determined when the function is called.

This says obj = {pet: "kitten", bed: "sleigh"} and checkProp = "gift" for the function call.

  1. checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "gift") should return the string pony .
  2. checkObj({pet: "kitten", bed: "sleigh"}, "gift") should return the string Not Found .
    both contains the same obj items

And

The objects look different to me

Still Stuck I think I should work hard to understand this.

Did you try deleting the part I said to delete?

yup and now I see blank

function checkObj(obj, checkProp) {
// Only change code below this line
obj = {

};

if(obj.hasOwnProperty(checkProp)) {
return obj[checkProp];
} else {
return “Not Found”;
}
// Only change code above this line
}

Delete all of this! The whole thing.

You mean like this:

function checkObj(obj, checkProp) {

// Only change code below this line

if(obj.hasOwnProperty(checkProp)) {

return obj[checkProp];

} else {

return "Not Found";

}

// Only change code above this line

}