Unable to pass the lesson even when the code seems to be correct

Tell us what’s happening:
I’m have code confirmation issues in Javascript : Testing Objects for Properties. Here’s my code so far. Can someone help?

// Setup
var myObj = {
gift: “pony”,
pet: “kitten”,
bed: “sleigh”
};

function checkObj(checkProp) {
// Your Code Here
if(myObj.hasOwnProperty(checkProp)){
return myObj[checkProp];
}
else if(myObj.hasOwnProperty(checkProp) !== true){
return “Not Found”;
}
else{
return “Change Me!”;
}
}

// Test your code by modifying these values
checkObj(“gift”);        
```js

// Setup
var myObj = {
gift: “pony”,
pet: “kitten”,
bed: “sleigh”
};

function checkObj(checkProp) {
// Your Code Here
if(myObj.hasOwnProperty(checkProp)){
return myObj[checkProp];
}
else if(myObj.hasOwnProperty(checkProp) !== true){
return “Not Found”;
}
else{
return “Change Me!”;
}
}

// Test your code by modifying these values
checkObj(“gift”);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.1 Safari/605.1.15.

Challenge: Testing Objects for Properties

Link to the challenge:

the code you are using is outdated

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

this is the starting code, and inside the function you need to have and use both parameters otherwise it will not work

I defined the function. if I’m not allowed to call the function how do I test it?

function checkObj(obj, checkProp) {
  // Only change code below this line
  if (obj.hasOwnProperty(checkProp)){
return 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.

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

You test the code by clicking Run the Tests : )

But if you want to play around with the code and see what happens for yourself, I’d recommend playing around with the code in a separate environment, such as an IDE or repl.it

1 Like

Thank you all for chiming in.
I found a solution in case someone comes across this

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

Your code has been blurred out to avoid spoiling a full working solution for other campers who may not yet want to see a complete solution. In the future, if you post a full passing solution to a challenge and have questions about it, please surround it with [spoiler] and [/spoiler] tags on the line above and below your solution code.

Thank you.

1 Like

you are not allowed to have extra code when running the tests
I usually add the function calls I need to test, and then delete those before running the tests

2 Likes