For the first if statement if I replace obj[checkProp] with just checkProp it gives me an error. I don’t understand why. Can someone please help me?
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
}
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36
You can’t access the name property by just using “name”.
You need to have this format: dog[name], there, you’re accessing the name.
In the challenge, you’re checking if a certain property exists on an object. So how else would you check it without accessing the properties first using bracket notation?
Also, bracket notation is used when using function parameters as the value of properties. Dot notation is if you’re accessing an specific property. You can access the example above using dot notation: dog.name
checkProp is a string, it’s possibly one of the keys of the object obj. Remember that objects consist of a group of key-value pairs. For this challenge, you need to return the value that corresponds to the key represented by checkProp.