Tell us what’s happening:
Why dot (.) property is not working in this function…?
Your code so far
function checkObj(obj, checkProp) {
// Only change code below this line
if(obj.hasOwnProperty(checkProp)){
// return obj[checkProp];
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/110.0.0.0 Safari/537.36
Challenge: Basic JavaScript - Testing Objects for Properties
checkProp is a parameter, which is just a variable. The variable contains a value and that value must be evaluated. obj[checkProp] will do just that and use the value stored inside the checkProp variable as the key for the object access.
const user = {
name: 'John'
}
const key = 'name'
console.log(user[key]) // John