Whats wrong with my code ? isdsd

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

  **Your code so far**

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

// 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/96.0.4664.45 Safari/537.36

Challenge: Testing Objects for Properties

Link to the challenge:

The basic answer is that you are overwriting obj with hardcoded data within your function as opposed to testing the object that is passed to checkObj to see if it has the property checkProp

2 Likes

Looking at your code more carefully I think I see why you are struggling.
You have worked out the logic… making a few minor typos along the way. Then when it hasn’t worked you’ve tried to do more in the process undoing what you had in the first place!

So:

  1. delete this:
obj={
  gift:"Pony"
  Pet:"Kitten"
  Bed:"Sleigh"
}
  1. Check this line for missing parenthesis AND a typo
if obj.hasOwnProperty(checkprop){
1 Like

This challenge is actually not well explain…
Even though I have done it but I still don’t understand

If you have questions about the challenge, please make your own topic asking for help.

1 Like

I found the typo but I can’t find the missing Paranthesis

What is your updated code?

function checkObj(obj, checkProp) {

  // Only change code below this line

 

  if obj.hasOwnProperty(checkProp){

    return obj[checkProp]

  }else if  {

    return "Not Found"

  };

 

  // Only change code above this line

}

This is incorrect syntax for an if statement. I’d look back on the lesson that introduces if.

This is also bad syntax. You should review the lesson that introduces else statements.