Testing Objects for Properties 2021

Tell us what’s happening:
Describe your issue in detail here.

This is the correct format. There has some glitch in the code terminal.
I HAVE TRIED in VS Code as per the “freeCodeCamp” tutorial taught by Beau.

var myObj = {

  gift: "pony",

  pet: " kitten",

  bed: "sleigh"


function checkObj(checkProp) {

  if (myObj.hasOwnProperty(checkProp)) {

    return myObj[checkProp];

  } else {

    return "Not Found"




  **Your browser information:**

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

Hi @Pallabi !

Welcome to the forum!

So I am a little confused by your question.

You have posted code for two different challenges.

Which one do you need help with?
The Testing objects one or the Replacing If Else Chains with Switch?

The Testing objects one

On the contrary I have solved it on VS Code but in here it’s showing error.

I edited your post to format your code and include the correct challenge.

The issue is that you are not supposed to create your own object.

This is incorrect

Also, you are missing a function parameter here

I would reset the lesson.

You should see two parameters when you reset the lesson

 checkObj(obj, checkProp)

You are not supposed to change that.

You need to test if obj has the property of checkProp.

Use this logic except change the myObj to obj.

Because you want to write a function that works with ANY object.

Not just one you hardcoded yourself.

Hope that makes sense!

1 Like

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

1 Like

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

    return obj[checkProp];

  } else {

    return "Not Found"



  // Only change code above this line

Thank you it worked.

I am glad you were able to pass the tests. :grinning:

Just to clarify, you don’t need to create an object at all.
This could be deleted.

You don’t want to hardcode these values because your function only works for that object.

Your function would technically fail if we had to test it against 100 different objects.

That is something to keep in mind for future challenges.

1 Like

It’s my first start into the world of programming. It’s good to have a great people support which ease the way of learning despite hurdles, it’s a great way to explore and learn .
I will keep this lesson in my mind long way to go.
Thank you again for the solution.
God bless you. :slight_smile:

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.