Is the "Testing Objects for Properties" exercise poorly designed or am I just missing something?

Tell us what’s happening:

I’m starting to doubt that this platform is actually useful for learning to code. These instructions suck. I’m an educator and I believe it is important to be as clear as possible with students new to a discipline. And I’ve helped my students get through a lot of frustration. These instructions are deviously unclear. And when I look at responses for others in the forms, I keep seeing, “the point is that you have to look in other places to find the answer”. So is the point of CodeCamp to present you with challenges that will force you to look elsewhere? If so, why not just use those other resources?

I’m seeing in the feedback this stuff about gift: “pony”, pet: “kitten”, bed: “sleigh”, but I don’t see anywhere in the code why it is that these terms are appearing. Are they somehow hidden from me? Where are they hidden? Is the point that they are hidden and that I need to deduce this fact from the response I receive? I don’t understand the purpose of this exercise.

The whole of the Java Curriculum has been crazy discouraging.

Your code so far


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

Your browser information:

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

Challenge: Testing Objects for Properties

Link to the challenge:

Hi and welcome to the forum.


The entire point of code is that you do not need to know every exact example for your code to function. Your function should work for any input object and string pair.

In this challenge, you are being asked to check the function argument obj has the property checkProp.

You should use the hasOwnProperty method as shown in the example. If obj has the property checkProp then you should return the value. Otherwise you should return the error message required.

When you have some code, we can help you debug it.


As a fellow educator who has years of experience teaching math and code at universities, I find the freeCodeCamp curriculum pretty good. We encourage students to look at a multitude of resources because

  1. it’s not possible to phrase any resource such that it’s a best fit for every student’s learning needs, and

  2. reading and understanding technical information from multiple sources is a critical skill for software development.

It’s perfectly normal to struggle to learn coding. It’s perfectly normal to get frustrated.

When you hit roadblocks or misunderstandings, that’s what the forum is for. As I am sure you know, written textbooks simply are not as good for learning as interacting with tutors and teachers.

1 Like

I agree that students learn in different ways and that direct feedback is the best way to learn. I just don’t get where the terms gift: “pony”, pet: “kitten”, bed: “sleigh” are being stored. Is the point that they are stored somewhere I can’t see? These instructions are ambiguous. The Java lessons have, at times, made these big leaps in difficulty that have been discouraging, but I usueally get the idea after looking in the forums. This is the first one that feels like it’s just poorly written.

I get that we’re trying to use .hasOwnProperty to find properties in our objects. I don’t get where the object is in the code that is written. I tried to enter this:

checkObj.hasOwnProperty();

I might have written that wrong, but I feel like I’m on the right track. I don’t get at all when the instructions say, "If the property is found, return that property’s value. If not, return `“Not Found” If I don’t know what properties I can look for, how am I supposed to look it up? Is the point that I don’t know what properties I am looking for and that when I test my code I will see the list of properties I can look up? Or was there something I could have done in the first place to see which properties I could have looked up?

FreeCodeCamp runs the listed tests with your solution to verify that it it correct. The test cases should not change your code at all, but they describe how we verify the correctness of an answer.

You can manually check some of the tests.

In this case, you could add

console.log(checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "gift"));

at the bottom of your code to see what happens when the test runs.


In this case, checkObj is the function. obj is the argument that holds an object. You should be checking the object obj for the property, not the functioncheckObj.

The property you are looking for is the checkProp.

You don’t need to know what specific objects and properties are being used when you write the function; that is the entire ‘big idea’ of code. The process to check an object for a property is the same no matter what object or property is being used.

Your object input will always be named obj inside the function. The property will always be in the variable checkProp.

I thought obj and checkProp were just parameters of the function. So obj is an Object, and it contains propositions I cannot see? And checkProp is a proposition?

If that’s the case, shouldn’t the code read something like this?

obj = {
prop: “checkProp”,
};

I changed my code to:

obj.hasOwnProperty(“checkProp”);

obj is a variable that holds an object. Your code doesn’t have to declare obj, only use it.

I think you’re missing the idea of variables here.

function printStuff(obj, checkProp) {
  // obj and checkProp are defined outside of the function
  console.log(obj);
  console.log(checkProp);
}

printStuff({gift: "pony", pet: "kitten", bed: "sleigh"}, "gift"));

no, beause the value of obj is determined when the function is called

so a function call like checkObj({name: "Freddie"}, "lastName") will determine the value of obj (as {name: "Freddie"}) and checkProp (as lastName)

the parameters take value from the function arguments, in order (first parameter from first argument etc)

if you look at the tests you can see various possible function calls

You can see what obj is by logging it to the console:

function checkObj(obj, checkProp) {
    console.log(obj)
}

But as someone already mentioned above, the whole point of the function you’re writing is that you don’t know beforehand what obj is, you don’t get to decide that. Your function is supposed to work with any object it gets called with. Its only purpose is to check if the property checkProp is present on obj. If I go ahead and call your function with obj={'smellsLike':'banana'} and checkProp='tastesLike', it should return Not Found. If I call it with checkProp='smellsLike', it should return banana.

(By the way, the language is called JavaScript, not Java - big difference. Just mentioning it because you’ll get far better search results if you google any questions and include the correct name of the language.)

I watched the video and found that the code is:

if (obj.hasOwnProperty(checkProp))
{return obj[checkProp];}
else
{return “Not Found”;}

This makes sense to me. But I still don’t understand what all the gift: “pony”, pet: “kitten”, bed: “sleigh” is all about. Ultimately, I feel like it doesn’t really matter. The thing is that all that stuff really started to confuse me and to make me question what I thought I had learned before.

I feel like the whole point of this exercise is just to plug .hasOwnProperty into a function. Which makes sense. If anyone else reads this thread, I reccomend to not pay attention to the “pony”, pet: “kitten”, bed: “sleigh” stuff. I didn’t even need it in the end.

But anyways, I appreciate people taking the time to respond.

The specific test cases are what objects and properties we will use as inputs when verifying your code. Like I said, and you said, the specific test cases should not change how you write your code. They are just there so you know how we test your code, and to let you test your code yourself.