Necesito ayuda por favor

Modifique la función checkObj para probar si un objeto pasado a la función ( obj ) contiene una propiedad específica ( checkProp ). Si se encuentra la propiedad, devuelva el valor de esa propiedad. Si no, regresa "Not Found" .


var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh"
};
function checkObj(checkProp) {

if (myObj.hasOwnProperty(checkProp)){
return myObj[checkProp];
} else {
return "Not Found";
}
}

checkObj("pet"); 
  **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.61 Safari/537.36

Challenge: Testing Objects for Properties

Link to the challenge:

It looks like you copied an old solution you found. Please don’t do this. You need to use the function signature that you were provided:

function checkObj(obj, checkProp) {
  // Only change code below this line
  return "Change Me!";
  // Only change code above this line
}

Notice that you removed the argument obj. Your function must have and use the argument obj.


Side note: it isn’t really helpful to copy-paste the challenge instructions into the post. It is much more helpful for you to describe what problem you are having in your own words. Programmers need to be able to communicate with other programmers about what problems they are having.

function checkObj(obj, checkProp) {

  // Only change code below this line

  if(obj.hasOwnProperty(checkProp)){

    return "checkProp" + obj[checkProp];

  }else{

    return "Not Found";

  }

  

  // Only change code above this line

}

es de esta manera…

Me pide unos objetos para devolver un objeto…no entiendo

What is this line doing? I don’t think it accomplishes this requirement:

If the property is found, return that property’s value.

Hmmm ok no era necesario, es que estoy un poco perdida.

The last code you posted is pretty close, you just have to return the actual property’s value instead of the value with the extra string added.

1 Like

gracias ya vi cual fue el error

function checkObj(obj, checkProp) {

  // Only change code below this line

  if(obj.hasOwnProperty(checkProp)) {

    return obj[checkProp];

  } else {

    return "Not Found";

  }

  // Only change code above this line

}
1 Like

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

vale, lo tendré en cuenta…Muchas gracias.

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.


This code does not use the early return pattern.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.