JavaScript básico - Verifica las propiedades de un objeto

Tell us what’s happening:

Describe tu problema en detalle aquí.

There are parts not working and I don’t understand why we need to rename property to checkProp, isnt it unnecesary?

Your code so far

function checkObj(obj, checkProp) {

  // Cambia solo el código debajo de esta línea

  if (checkObj.hasOwnProperty(checkProp)){

    return obj[checkProp];  

  }else {

    return "Not Found";

  }

}

checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "gift");
checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "pet");
checkObj({city: "Seattle"}, "city");

  // Cambia solo el código encima de esta línea

Your browser information:

El agente de usuario es: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36

Challenge Information:

JavaScript básico - Verifica las propiedades de un objeto

if the object obj has the property checkProp

Excuse me, question, why is this Thread not listed under Javascript section?

It’s just listed in the Spanish JS section. If you use the curriculum in that language it will open the help thread in the appropriate language section (I assume).

1 Like

Thanks.

Ok, so this is my code and its not working, any ideas?


function checkObj(obj, checkProp) {

  // Cambia solo el código debajo de esta línea

  if (checkObj.hasOwnProperty(checkProp)){

    return obj[checkProp];  

  }else {

    return "Not Found";

  }

}

checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "gift");
checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "pet");
checkObj({city: "Seattle"}, "city");

  // Cambia solo el código encima de esta línea

6 hours and there’s no reply, is anyone here?

Han pasado 6 horas y no ha contestado nadie, ¿hay alguien aquí?

is not working because there is an error in the if statement. The checkProp variable should be checked against the obj parameter, not against checkObj.

1 Like

You were right about that, thanks very much.

1 Like