Tell us what’s happening:
Got all checks passed except the one
checkObj({pet: "kitten", bed: "sleigh"}, "gift") should return "Not Found" .
I guess I have to check it once and then remove the ‘pony’ from the object. so it will get a not found
tried to do delete myObj[“pony”];
but that diden’t work.
Your code so far
function checkObj(obj, checkProp) {
// Only change code below this line
var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh",
city: "Seattle",
};
if (myObj.hasOwnProperty(checkProp)){
return obj[checkProp];
}
else {
return "Not Found";
}
// Only change code above this line
}
well I did define the object there because of these… I assumed that I had to do everything inside of these. Or I am allowed to define stuff outside of these?
// Only change code below this line
// Only change code above this line
Sure, you can, but then your function is not checking if the obj used in the function call has the checkProp. The function call only checks the hardcoded myObj.
The challenge wants the function to work for anyobj.
No one is telling you not to use a return. You shouldn’t be writing your own object.
Take a look at your logic here:
You are checking whether an object that you created contains a property, then returning that property in a different object that you received as an argument.
You never need myObj. All of the checks should be on obj.
So the object already exists from the beginning? even if you can’t see it among the code?
Ah tried this and now I passed. Thanks everyone for your help .
I assumed I had to create the object because I diden’t see it.