Testing Objects for Properties exercise struggle

Tell us what’s happening:
Describe your issue in detail here.
Hi, I’ ve been trying to solve this excercise several time, I ended up using the solution in the section “Get a Hint” and it worked.
But I am uder the impression that it could be better explained, provide more informations to guide the learner towards the correct solution.
Even concerning the syntax, I believe that who arrives at this point without previous knowledge, struggles a lot to go on.

  **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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36

Challenge: Testing Objects for Properties

Link to the challenge:

Yeah, this is tough stuff. And JS is harder than what came before. And this challenge is a tough one.

But the learner should have enough information at this point to solve this. Again, I’m not saying that it is easy. But it’s supposed to be tough.

And you definitely will learn a lot more if you figure it out on your own. Rather than look at the answer, I would recommend using the "Get Help → Ask for Help` button and we can give you a hint in the right direction, or explain a concept that is troubling you. One of the biggest mistakes learners make is not asking for help. And not googling things - that is a big (not really a) secret of professional developer - we are googling thing … all … the … time. No one can remember all this stuff. And as a professional dev, there will be many times when you don’t have every piece to solve a problem and you have to search for it.

Did you understand the solution? Could you redo it now, from scratch?

Hi,
Thank you for your reply.

I understand that learning is a process. Honestly, I still don’t get the solution. I believe that I should go back and repeat some lessons, since it’s not very clear to me how to create a little-more-than-basic function, not yet!
Do you have any suggestions? Good articles?

Thanks.

Repeating lessons you already understand doesn’t always help. Sometimes it does and sometimes its more procrastination than benefit.

In this case, I would try to describe what you think the instructions are saying. Then I would describe to us how you would accomplish this task without code. From there we can look at where you are having trouble translating that understanding into code.

Hi,
thank you for your reply.

So, what I understand is:
I’m asked to write a function that verifies if an object passed to a function contains a specific property. Here I already have a struggle, because so far I saw how to test if an object (object only) has got a property. I don’ t know exactly how to test an object passed to a function. I am not sure if I’m explaining myself correctly.

What I don’t understand is if I have to write an object, or if the object is already there and where. The function is:

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

What I understood is that (obj, checkProp) are parameters, but it seems instead that “obj” is already an object? Or do I have to write an object inside the function?

Thanks.

Hi @andreacer !
Welcome to the forum!

It sounds like there is confusion on how function calls work.
The lesson teaches you about hasOwnProperty which is what you will need to use in this challenge.

In your function you are basically checking if the property exists in the object.
If so, then return the property’s value.
If the property does not exist, then you will return Not Found.

In your function you are not supposed to create an object.
You will need to use the obj and checkProp parameters.

When you call the function you will pass in an actual object and parameter name.
For example,

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

No.

When the function is called, that is the object you are testing.
Here are example function calls with different objects being used.

checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "pet")
checkObj({city: "Seattle"}, "city")

Your function should work for 100’s of function calls.
That is why you will not be creating your own objects.
That is also why we use parameters because they are placeholders for the actual values when we call the function.
Using parameters allows use to use the same function 100’s of times.

Hope that helps!

1 Like