Testing Objects for Properties help!

Tell us what’s happening:
I can’t seem to figure this out. The goal is to determine if the property the function accepts is a property in the object. If yes, then return that property. If no, return ‘Not Found’.

I’m stuck – can anyone help?

Thanks!

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

function checkObj(checkProp) {
  // Your Code Here

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

// 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 {
    return "Not Found";
  }
  }

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

Your browser information:

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

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/testing-objects-for-properties/

Hi,

You almost have it.

Review dot notation vs bracket notation for accessing object properties.

Good luck!

Thanks! Figured it out :slight_smile: