Stuck on this 'Testing Objects for Properties' Exercise

Tell us what’s happening:
Hi, I’m having trouble with this problem. I need some help, please. I don’t understand, and I would like someone to help me understand, please, and Thank you kindly!

Your code so far
var myObj = {
gift: “pony”,
pet: “kitten”,
bed: “sleigh”

return “Change Me!”;

function checkObj(obj, checkProp) {
// Only change code below this line
var myObj = {
  gift: "pony",
  pet: "kitten",
  bed: "sleigh"

return "Change Me!";
// Only change code above this line

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_0_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36.

Challenge: Testing Objects for Properties

Link to the challenge:

Here you go…

function checkObj(obj, checkProp) {

if(obj.hasOwnProperty(checkProp)) {
     return obj[checkProp]
}  else {
    return 'Not Found'


The function takes 2 arguments but you are not using them…you are adding the object inside the function but the exercise is asking you to do it dynamically…otherwise you will have to repeat the process 8 times(put 8 different objects overtime and check if they meet the conditions).
The method hasOwnProperty is accessing to the object by using the ’ . ’

The exercise is asking you to return something based on the conditions met.

Hope it helps… :slight_smile:

1 Like

I understand it a lot better, thanks to you!

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 (’).

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.

You can post solutions that invite discussion (like asking how the solution works, or asking about certain parts of the solution). But please don’t just post your solution for the sake of sharing it.
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.