// Establezco la variable
var myObj = {
gift: “pony”,
pet: “kitten”,
bed: “sleigh”,
city: “Seattle”
};
function checkObj(obj, checkProp) {
if (myObj.hasOwnProperty(checkProp)) {
return myObj[checkProp]}
else {return"Not Found"}
};
Necesito ayuda con este ejercicio, nose porque me pide que en un momento gift sea igual a pony y en otro momento que gift sea igual a not found.
No se la manera en la puedo hacer eso, ayuda porfavor.
checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "gift")
debe devolver la cadena pony
.
checkObj({pet: "kitten", bed: "sleigh"}, "gift")
debe devolver la cadena Not Found
.
Estas dos cosas me pide.
Inside your function you are using myObj. You should not be using that, it should not exist. you should be using the object that is passed into the function.
1 Like
Still not understanding, i keep trying but it doesnt work
Can you provide a link to the challenge so we can provide a more concrete explanation?
Its okey, i already made it right, thank you!
1 Like
function checkObj(obj, checkProp) {
// Cambia solo el código debajo de esta línea
var myObj ={
gift: “pony”,
pet: “kitten”,
bed: “sleigh”,
city: “Seattle”
};
if (obj.hasOwnProperty(checkProp)){
return myObj[checkProp];
} else if (obj.hasOwnProperty(checkProp) !== true){
return “Not Found”;
} else{
return ;}
// Cambia solo el código encima de esta línea
}
// Cambia solo el código encima de esta línea//
console.log(checkObj(“district”));
1 Like
Sigo sin entender por que obj y checkProp que son argumentos de la función se pueden buscar en el objeto myObj,
Me pueden explicar?