Tell us what’s happening:
Testing Objects for Properties
The var myObj seems to be missing as it is the variable containing the information:
var myObj = {
gift: “pony”,
pet: “kitten”,
bed: “sleigh”,
city: “Seattle”
};
I added myObj. Then the ‘Not Found’ worked. From the function line
function checkObj(Obj, checkProp) {
The arg is passed into the Obj arg, as of yet I have not found checkProp to contain data. When I put in ‘gift’ the console.log(checkObj(“gift”)); Returns pony, but the test comes back, " should return the string pony
." which the console.log indicates is being returned.
**Your code so far**
var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh",
city: "Seattle"
};
function checkObj(Obj, checkProp) {
var answer = “”;
console.log(myObj[Obj]);
if (myObj.hasOwnProperty(Obj)){
console.log(myObj[Obj]);
return myObj[Obj];
}
//if (myObj.hasOwnProperty(Obj)) {
// console.log(“It was true”);
// console.log(Obj);
// checkProp = myObj[Obj];
// console.log(checkProp + " the answer!");
// checkProp = myObj[Obj];
// console.log(checkProp + " is the contents of checkProp");
// return checkProp;
else {
return "Not Found";
}
// Only change code above this line
}
console.log(checkObj(“city”));
console.log(checkObj(“gift”)+ " testing");
function checkObj(Obj, checkProp) {
// Only change code below this line
var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh",
city: "Seattle"
};
var answer = "";
console.log(myObj[Obj]);
if(myObj.hasOwnProperty(Obj)){
return myObj[Obj];
//if (myObj.hasOwnProperty(Obj)) {
// console.log("It was true");
// console.log(Obj);
// checkProp = myObj[Obj];
// console.log(checkProp + " the answer!");
// checkProp = myObj[Obj];
// console.log(checkProp + " is the contents of checkProp");
// return checkProp;
} else {
return "Not Found";
}
// Only change code above this line
}
console.log(checkObj("city"));
console.log(checkObj("gift")+ " testing");
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36
Challenge: Testing Objects for Properties
Link to the challenge: