# Testing Objects for Properties -How do we do this?

**URL:** <https://forum.freecodecamp.org/t/testing-objects-for-properties-how-do-we-do-this/143226>\
**Category:** General\
**Created:** [August 22, 2017, 7:05pm UTC](https://forum.freecodecamp.org/t/testing-objects-for-properties-how-do-we-do-this/143226 "2017-08-22T19:05:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Murrium123](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/murrium123/32/86847_2.png) [@Murrium123](https://forum.freecodecamp.org/u/Murrium123)\
**Post date:** [August 22, 2017, 7:05pm UTC](https://forum.freecodecamp.org/t/testing-objects-for-properties-how-do-we-do-this/143226/1 "2017-08-22T19:05:38Z")

</div>

**Tell us what’s happening:**  
I think I am supposed to use an if /else statement to fix this but the logic doesn’t make sense to me.

**Your code so far**

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

function checkObj(checkProp) {
  // Your Code Here
if myObj.checkObj(checkProp) return ""; // true
myObj.checkObj();  
  return "Change Me!";
}

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

```

**Your browser information:**

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

**Link to the challenge:**  
[https://www.freecodecamp.org/challenges/testing-objects-for-properties](https://www.freecodecamp.org/challenges/testing-objects-for-properties)

---

<div class="post-metadata">

**Author:** ![sheenvishen](https://avatars.discourse-cdn.com/v4/letter/s/aeb1de/32.png) [@sheenvishen](https://forum.freecodecamp.org/u/sheenvishen)\
**Post date:** [August 26, 2017, 7:26am UTC](https://forum.freecodecamp.org/t/testing-objects-for-properties-how-do-we-do-this/143226/3 "2017-08-26T07:26:47Z")

</div>

[https://www.freecodecamp.org/challenges/testing-objects-for-properties](https://www.freecodecamp.org/challenges/testing-objects-for-properties)

return “Not Found” doesn’t work. Can you tell me what’s wrong with my code?

---

<div class="post-metadata">

**Author:** ![sheenvishen](https://avatars.discourse-cdn.com/v4/letter/s/aeb1de/32.png) [@sheenvishen](https://forum.freecodecamp.org/u/sheenvishen)\
**Post date:** [August 26, 2017, 9:07am UTC](https://forum.freecodecamp.org/t/testing-objects-for-properties-how-do-we-do-this/143226/5 "2017-08-26T09:07:14Z")

</div>

```auto
var myObj = {
  gift: "pony",
  pet: "kitten",
  bed: "sleigh"
};

function checkObj(checkProp) {
  // Your Code Here
  myObj.hasOwnProperty(checkProp);
  if (checkProp) 
    return myObj[checkProp];
  else 
    return "Not Found";
}

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

```

---

<div class="post-metadata">

**Author:** ![sheenvishen](https://avatars.discourse-cdn.com/v4/letter/s/aeb1de/32.png) [@sheenvishen](https://forum.freecodecamp.org/u/sheenvishen)\
**Post date:** [August 26, 2017, 9:40am UTC](https://forum.freecodecamp.org/t/testing-objects-for-properties-how-do-we-do-this/143226/7 "2017-08-26T09:40:37Z")

</div>

Got it. Thanks for your help. I’ll make use of the back ticks next time for posting my code.

---

<div class="post-metadata">

**Author:** ![halfpintutopia](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/halfpintutopia/32/90826_2.png) [@halfpintutopia](https://forum.freecodecamp.org/u/halfpintutopia)\
**Post date:** [September 29, 2017, 10:34am UTC](https://forum.freecodecamp.org/t/testing-objects-for-properties-how-do-we-do-this/143226/8 "2017-09-29T10:34:43Z")

</div>

**Tell us what’s happening:**  
Please, could someone help me figure this out?!

I found this a bit challenging and but after playing around I got the code below - which gave me an error for the last test (checkObj(“house”) should return “Not Found”).

I went onto the forum for some much-appreciated guidance and found someone had created this solution which worked, but for the life of me I can’t see the error or difference in my code. I also added “return “Change Me!”;” but the last test did not work:

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

return “Change Me!”;  
}

**Your code so far**

```auto
// 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:**

Your Browser User Agent is: `Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36`.

**Link to the challenge:**

> **[Learn to code with free online courses, programming projects, and interview...](https://www.freecodecamp.org/challenges/testing-objects-for-properties)**
>
> Learn to code with free online courses, programming projects, and interview preparation for developer jobs.

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 17, 2021, 8:38pm UTC](https://forum.freecodecamp.org/t/testing-objects-for-properties-how-do-we-do-this/143226/9 "2021-01-17T20:38:42Z")

</div>

Closed on January 17, 2021, 8:38pm UTC


