Can you elaborate on why my solution here is incorrect?
Thank you.
**Your code so far**
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
}
**Your browser information:**
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.1 Safari/605.1.15
Here’s what the challenge wants. Am I missing something?
Modify the function checkObj to test if an object passed to the function ( obj ) contains a specific property ( checkProp ). If the property is found, return that property’s value. If not, return "Not Found" .
Property names are just strings. You are missing my point though. "top" and "middle" are strings while checkProp is a variable that holds a string. Do you put quotation marks around a variable to use it?
Modify the function checkObj to test if an object passed to the function ( obj ) contains a specific property ( checkProp ). If the property is found, return that property’s value. If not, return "Not Found" .
“checkProp” is a property (of the object “obj”), not a standart “variable that holds a string”.
checkObj is a function. The checkObj function takes two arguments, obj and checkProp. The obj argument is a variable holding the object that you want to check. The checkProp argument is a variable holding the string with the property name you want to check for.
Your syntax is mostly right, but you are not treating checkProp like a variable.
const myProp = "this is some string property name";
console.log(myProp); // Notice no quotation marks here!
I didn’t use quotation marks around my myProp variable above when I used it inside of the console.log() function.
Remember that checkProp acts as a placeholder for the real values which in this function call would be “gift”.
Hopefully that makes sense.
The last thing we have to change is this part here
You can’t use dot notation here. We have to use bracket notation.
We should only use dot notation if we know the property’s name.
In this case, checkProp is a parameter and acts as a placeholder for the real value.
We can have dozens of function calls where the value of checkProp will be different each time depending on the values in the function call.
I really hope all of this makes sense.
You are really close to solving the challenge.
You just have to make those two changes to your code to pass.