Bug in the Question

Tell us what’s happening:
So question demands 2 thing which are contradictory and wont let the level move ahead.

  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 .

    Your code so far


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

return "Change Me!";
// Only change code above this line
}
  **Your browser information:**

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

Challenge: Testing Objects for Properties

Link to the challenge:

Here is your bug. The instructions did not tell you to insert this hard-coded object into your function.

2 Likes

they are not contradictory

this one is checking the object {gift: "pony", pet: "kitten", bed: "sleigh"}, which contains the gift property with a value of "pony"

this one is checking the object {pet: "kitten", bed: "sleigh"} which does not have the gift property

notice that you overwrite the value of the first parameter, instead of using the objecy passed in

3 Likes

@JeremyLT @ilenia
got it… thanks a lot

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