Tell us what’s happening:
guys i need help with this,I am stuck
Your code so far
function checkObj(obj,checkProp) {
// Only change code below this line
var myObj = {
gift:"pony",
pet: "kitten",
bed: "sleigh",
city:"Seattle"
};
if (myObj.hasOwnProperty(checkProp)) {
return obj[checkProp];
} else {
return "Not Found";
}
checkObj()
return "Change Me!";
// Only change code above this line
}
Your browser information:
User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0.
you have created your own object myObj, which is not what the challenge asks (or is about). The object to check will be provided as a function argument, so you don’t need to define one yourself.
The task is then to check if a certain property (checkProp - the second function argument) is a property on the given obj.
The first thing you’d have to do is delete that object myObj you’ve created. Then just run the function and at the beginning, see what’s passed to the function:
function checkObj(obj,checkProp) {
// Only change code below this line
console.log(obj);
// Only change code above this line
}
That should show you why you don’t need to create your own object.
no, sorry, here in the forum we don’t share solutions.
You are not obligated to do the challenges, you can go to next one if you don’t like this one.
I’m trying to give you hints on how to pass the challenge, which boils down to: you are not testing the object you are given through the function parameter obj
Hey @ser1, firstly their is no need to panic. Read the instructions given for solving the problem carefully. If you still haven’t deleted the object myObj you have to do that then. Next, just use the if-else statements you have used but with the checkObj function arguments which are obj and checkProp respectively.
As mentioned earlier by @ILM the challenges are technically optional for the certificates. The forum does not encourage sharing solutions but rather guiding you to the right solution.
If you want to post your updated code we can help you from there.
var myObj = {
gift ="pony",
pet = "kitten",
bed = "sleigh",
city ="Seattle"
};
if (myObj.hasOwnProperty(checkProp)) {
return obj[checkProp];
} else {
return "Not Found";
}
checkObj()