Can't figure out why it isn't working

Tell us what’s happening:
the issue here is that I can’t seem to print these values for “not found” as required

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

Your code so far



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

function checkObj(obj,checkProp) {
// Your Code Here
if(myObj.hasOwnProperty(checkProp)){
return myObj[checkProp];
}
else if(myObj.hasOwnProperty(checkProp) !== true){
return "Not Found";
}
else{
return "Change Me!";
}
}

// Test your code by modifying these values
checkObj("gift");

Your browser information:

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

Challenge: Testing Objects for Properties

Link to the challenge:

You don’t want to check the myObj object. You want to check the object that was passed into the function (i.e. the obj object).

2 Likes

Thanks, now I understand it better even. Totally makes sense, you want to check the properties of an object.

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