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
}
Your browser information:
User Agent is: Mozilla/5.0 (Linux; Android 8.1.0; Infinix X5515 Build/O11019) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Mobile Safari/537.36.
your mistake is in the if if(checkObj.hasOwnProperty(checkProp))
There you are calling the function instead of the object that was passed as a parameter to the function
Aight, so
This function works to see whether an object has a property. If it does have the property. It will return the value held in the property. If it does not have the property, it will return “Not Found”
It takes in obj and checkProp as properties. This is so that you can use the function on any object elsewhere since you’ll pass in the name of the object you want to check as the first parameter and the name of the property that you want to confirm is in the object as the second parameter.
Where you went wrong is in the if statement. The hasOwnProperty method won’t work on a function. It only works on an object. And in this case you have an object which you passed as a parameter to the function
If you remember in object lookups where you go obj[propertyName]
This is the same case here
It’s checking if obj has a property called propertyName and if it does. Return obj[propertyName]
and i wanted to see whether there is a number 3 in the object. I would use checkObj as follows checkObj(Numbers, three)
This would return 3 since Numbers does indeed have a property called three
if i did checkObj(Numbers, four) it would return Not Found since there is no property called four in Numbers
You are on the right way with your code but there is a typo in it!
You have to check if the parameter of the function obj has hasOwnProperty(checkProp) and not the function itself!
@JudgeFudge19 has already mentioned it!
If you have more questions do not hesitate to contact us!
var myObj = {
gift:"pony",
pet:"kitten"
bed:"sleigh"
}
function checkObj(checkProp){
if(myObj.hasOwnProperty(checkProp){
return myObj.checkProp;
}else{
return "Not Found" } ```
Pls have look becoming angry😅
@rielka pls have a look too
It does not work because it is an other function as excepted in the challenge!
The function is: function checkObj(obj, checkProp)
You have an Object ‘ob’j’ and you should check if it has ‘hasOwnProperty’!
Your first code was really OK!
Instead of using: if(checkObj.hasOwnProperty(checkProp))
replace it with: if(obj.hasOwnProperty(checkProp))
and do not change the rest of the code and your code will work!
And above all forget the code that you have just posted!
function checkObj(obj,checkProp){
if(obj.hasOwnProperty(checkProp){
return obj.checkProp}
else{
return "Not Found"}
}
Cos it doesn’t work for me
And when I try to understand the syntax function checkObj(obj(*why didn't the give us a real obj to work on*,checkProp)
If I am to console.log what’s above how will i write it
Pls @arielka help😔
Tell us what’s happening:
I can not spot the error here
Pls help
Your code so far
var myObj = {
gift:"pony",
pet:"kitten",
bed:"sleigh"
};
function checkObj(checkProp) {
if(myObj.hasOwnProperty(checkProp)){
return myObj[checkProp];
}else{
return "Not Found"
}
// Only change code below this line
// return "Change Me!";
// Only change code above this line
}
Your browser information:
User Agent is: Mozilla/5.0 (Linux; Android 8.1.0; Infinix X5515 Build/O11019) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Mobile Safari/537.36.