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
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
}
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
}
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.
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.