Tell us what’s happening:
I don’t even know where to get started with this task Where on earth did pony, kitten, etc come from? Can anyone help me get started?
Your code so far
function checkObj(obj, checkProp) {
// Only change code below this line
return "Change Me!";
// Only change code above this line
}
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36
Challenge: Basic JavaScript - Testing Objects for Properties
I’m not sure what that means but I’ve got this far with a bit more luck but am now stuck again:
function checkObj(obj, checkProp) {
// Only change code below this line
gift: "pony",
pet: "kitten",
bed: "sleigh"
};
checkObj.hasOwnProperty("gift");
checkObj.hasOwnProperty("pet");
return "Not Found";
// Only change code above this line
}
Why are you adding all of this? What is your logic to solve the challenge?
Do you understand what the parameters of the function represent? Do you understand how functions pass values (arguments) to functions and how they can be referenced inside a function?
The tests list several function calls that will be executed with your function. Those function calls have specific values for the arguments obj and checkProp. You can inside of your function use obj and checkProp like any other variable.
So the instructions are asking you to write the logic to determine if the object obj has the property checkProp.
function checkObj(obj, checkProp) {
// Only change code below this line
checkObj.hasOwnProperty("obj");
checkObj.hasOwnProperty("checkProp");
return "Not Found";
// Only change code above this line
}
Still no good. I can’t quite understand what it’s asking?!?
Tell us what’s happening:
Hi - I’m still on this and have tried a variety of approaches with no success based on what I think it is saying. Can anyone help please?
Your code so far
function checkObj(obj, checkProp) {
// Only change code below this line
checkObj.hasOwnProperty("checkProp");
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/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36
Challenge: Basic JavaScript - Testing Objects for Properties
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" .
The checkObj does not exist. You cannot use a variable that is not defined… Only obj exists
You are not looking for a property called "checkProp", you are looking for a property with the name stored in the checkProp variable
Also, your return statement is going to always say that you did not find the property. You will need some logic to return differently based upon if obj has the property given by the name stored in checkProp
Ok, cool. So what property is the question asking me to find? I keep reading it and it sounds like:
obj.hasOwnProperty(“checkProp”);
return “Not Found”;