Help with basic java script

Hi

I am struggling with basic java script point 90 - testing objects for properties .

this is what i have dne so far

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

  function checkObj(obj, checkProp) {
  if (obj.hasOwnProperty(checkProp)) {
    return obj[checkProp];
  } else {
    return "Not Found";
  }
}
  // Only change code above this line
}

any help greatful

thanks

Karl.

Can you share a link to the step? Can you talk about how you are stuck? Thanks

You probably shouldn’t copy-paste that function definition you found into your function definition - that won’t do what you want it to do.

Any help mate?
think i just need pointing in the right way

Karl.

Hi there!
Welcome to the forum. The above link redirect to the main curriculum. Post link to the challenge step you are doing right now.

https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/testing-objects-for-properties

I’d start out by removing the stuff you copy-pasted from somewhere.

You also should not try to define any new objects inside of your function.

What code had you tried before you looked up the solution hint?

the idea the obj was to tell it what was right

i am not doing that now.

this is what i am doing

function checkObj(obj, checkProp) {
  // Only change code below this line
  if (checkObj.hasOwnProperty(checkProp)){
   return checkObj.[checkProp];
}else {
  return "Not Found";
}
  // Only change code above this line
}

That’s all of your code?

This has a small issue, you can’t combine bracket and dot notation like that.

what do i need to do ?

Choose one. If it doesn’t work try the other one.

Also you are using the function name, instead of object obj.
Instructions:test if the object passed to the function parameter obj contains the specific property passed to the function parameter checkProp. If the property passed to checkProp is found on obj, return that property’s value.

You need to not mix and match dot and bracket notation. What does your code look like if you pick only one where I quoted?

got it, took ages , cant belive how simple it was
thank u !!

1 Like

i got it ,

thanks , so much for your help

karl.

1 Like

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