Tell us what’s happening:
Why is the console returning undefined? i used an if statement. If the value of obj.hasOwnProperty(checkProp) equals true, then return the value of property of object, else return the string “Not Found”. Problem is that in the case obj.hasOwnProperty(checkProp) is false, it’s returning “Not Found”, but in the case true, it’s returning undefined, not the value of obj.checkProp. Can anyone please tell where i am getting wrong?
Your code so far
function checkObj(obj, checkProp) {
// Only change code below this line
if(obj.hasOwnProperty(checkProp) == true) {
return obj["checkProp"];
}
else {
return "Not Found";
}
// Only change code above this line
}
console.log(checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "gift"));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36
Challenge Information:
Basic JavaScript - Testing Objects for Properties