I am a bit stuck in this exercise.
I looked at other’s solutions but I don’t understand how to make the computer to understand that when myObj.hasOwnProperty(checkprop) === city {
return "Seattle}
Could anyone explain step by step what are we trying to achieve please?
Here is the code so far:
function checkObj(myObj, checkProp) {
var myObj = {
gift: “pony”,
pet: “kitten”,
bed: “sleigh”,
}
if (myObj.hasOwnProperty(checkProp)) {
return(myObj[checkProp]);
} else {
return “Not Found”;
}
// Only change code above this line
}
checkObj(“gift”)
Your code so far
function checkObj(myObj, checkProp) {
// Only change code below this line
var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh",
}
if (myObj.hasOwnProperty(checkProp)) {
return(myObj[checkProp]);
} else {
return "Not Found";
}
// Only change code above this line
}
checkObj("gift")
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36
.
Challenge: Testing Objects for Properties
Link to the challenge: