Am Sorry
I did not realise
That is your first code:
function checkObj(obj, checkProp) {
// Only change code below this line
if(checkObj.hasOwnProperty(checkProp)){
return obj[checkProp];
}
else
{
return "Not Found";
}
//return "Change Me!";
// Only change code above this line
}
Please adjust it according to the recommendation of @ lasjorg:
if( obj.hasOwnProperty(checkProp) )
Dude
please follow the instructions. You are not really required to console.log out the function. You are asked to check whether obj
has a property checkProp
. If it does have it return the value of checkProp
. If it does not return the string ‘Not Found’
I was able to pass it
But will not mind if u explain to me
function checkObj(obj,checkProp)
If I am to pass a param how will it work
And I am so grateful to u today thank you
You first need to understand how function parameters work and how to use them
for instance, if i were to write a function that adds two numbers , logs out the result of the addition and returns their sum it would look like this:
function add(a,b) {
let sum = a + b;
console.log(sum);
return sum;
}
Parameters allow me to add whatever two numbers i would like when i use the function(which is when i call it) eg
// to add 5 and 6
add(5,6);
in this case a becomes 5
and b becomes 6
I know how function works
But now I want to know how that testing objects function works
PL I don’t want to disturb you
I only want to learn