Testing objects for properties; lesson 90

it is still telling me i have 3 errors
im even following an example on youtube

  **Your code so far**

// Setup
var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh",
city: "Seattle"

function checkObj(checkProp) {
// Your code here
var answer = "Not Found";

if (myObj.hasOwnProperty(checkProp)) {
  answer = myObj[checkProp];

return answer;
// Test your code by modifiying these values

  **Your browser information:**

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

Challenge: Testing Objects for Properties

Link to the challenge:

You changed the function signature. You must not do this. You have to use the code given to you instead of replacing it with a different problem.

i changed the function from

function checkObj(checkProp)
function checkObj(checkProp)

it still says that “gift” should = to “Not Found”
The rest is right i assume

No. Parts of your code are right, but you still have the wrong function signature.

function checkObj(obj, checkProp) {

It looks like maybe you found an old solution somewhere and tried to duplicate that solution instead of using the code you were given.

i switched it back but its still wrong

Switched it back to what? You haven’t shown any code with the correct signature yet.

function checkObj(checkProp)

This one is wrong, all three times you posted it. You need the one with obj.

switched back to this

function checkObj(obj, checkProp)

Ok. Did you use obj in your code after fixing the function signature? You shouldn’t reference any variables from outside of your function. I.e. you can’t use myObj in your function or it won’t be able to work on any other obj that gets passed in.

Hi @Ggm6101421 !

This is an issue.

You are not supposed to create your own object.

The reason why is that you want to create a function that works for ANY object.
Not just one you created yourself.

What if you wanted to test your function on 100 different objects?
You wouldn’t hard code 100 different key value pairs for an object just for your function to work.

Delete this

For your code here, only reference the obj parameter

When you do that then the test will pass.

Then when you call the function, that is where you will pass in an actual object and property name.

For example,

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

Hope that makes sense!

1 Like

thanks that was the problem

details had me getting frustrated
that myObj to obj helped me pass

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