Code is not work

Tell us what’s happening:

the code is not working I don’t know why can you help me?

Your code so far


var obj = {
 gift : "pony",
 pet : "kitten",
 bed : "sleigh"
};

function checkObj(checkProp) {
 // Only change code below this line

if(obj.hasOwnProperty(checkProp)){
  return obj.checkProp;
}else{
  return "Not Found";
}
 return "Change Me!";
 // Only change code above this line
}

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36.

Challenge: Testing Objects for Properties

Link to the challenge:

First, reset the code for the challenge. It should look like

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

Do not change anything other than removing the current return statement and putting your own code in between the two comments. Also, you can ignore the video completely (if you have looked at it). It pertains to an older version of this challenge.

1 Like

I tried all the possibilities

Hi, I think the clause if doesn’t work because the last return always run. ¿What do you think?

Please show us your most recent try here and then we can help you.

maybe sir what you suggest now?

function checkObj(checkProp) {

  // Only change code below this line

var obj = {

  gift : "pony",

  pet : "kitten",

  bed : "sleigh"

};

 if(obj.hasOwnProperty(checkProp)){

   return obj[checkProp];

 }else{

   return "Not Found";

 }

  return "Change Me!";

  // Only change code above this line

}

For future reference, you need to begin your code with three backticks and then end it with three backs so that it formats properly in the forum.

What you just posted is not the correct function definition for the current challenge. Did you click on the “Reset All Code” button to reset the challenge?

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.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.

markdown_Forums


You have change the function definition.

  1. Like said, either reset the code and use the parameters obj and checkProp, or add the obj parameter back again.

  2. checkProp is a string, you can not use dot notation with in.

1 Like

thank you so much, sir, my code is working now