Tell us what’s happening:
I have done this exercise as it is explained on the video, which to me makes total sense. However I am not passing this test and when I reset the code it gives me this:
function checkObj(obj, checkProp) {
// Only change code below this line
return “Change Me!”;
// Only change code above this line
A function where the user is gonna input the object and ask to check if it has a certain property. Why would it need to ask for checking anything, if the user is inputting all the properties? It makes no sense to me. My code below is similar to the one on the video but the code is not passing the test Your code so far
var obj = {
"gift": "pony",
"pet": "kitten",
"bed": "sleigh",
"city": "Seattle"
}
function checkObj(checkProp) {
var checkProp;
if (obj.hasOwnProperty(checkProp))
{
return obj[checkProp]
}
else {
return "Not Found"
}
}
console.log(checkObj("city"))
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.149 Safari/537.36.
Hi. It isn’t made explicit in the challenge introduction, but function checkObj should have two arguments, a first one for the object and a second one for the property to check. Even though you are checking if a property exists for the object obj, which is declared globally, you may want to use the same function for a different object.
Videos have helped me a lot. I like how the guy explains it all, sometimes the written instructions are not clear enough.
I got confused because the video and the instructions on this one were greatly different.
Anyway, I skipped this one and then came back to it with its solution, thanks people.
function checkObj(obj, checkProp) {
// Only change code below this line
if (obj.hasOwnProperty(checkProp))
{
return obj[checkProp];
}
else {
return "Not Found";
}
// Only change code above this line
}
console.log(checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "gift"))