Basic JavaScript - Testing Objects for Properties

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
 ;
 // Only change code above this line
}
   **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Firefox/102.0

Challenge: Basic JavaScript - Testing Objects for Properties

Link to the challenge:

You didn’t add any code to the function. Do you have a specific question about this challenge?

2 Likes

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
return "Change Me!";
// Only change code above this line
}

Modify the function checkObj to test if an object passed to the function (obj) contains a specific property (checkProp). If the property is found, return that property’s value. If not, return "Not Found".

  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Firefox/102.0

Challenge: Basic JavaScript - Testing Objects for Properties

Link to the challenge:

what have you tried? please show your code

 var myObj = {
    gift: "pony",
    pet: "kitten",
    bed: "sleigh",
  };

  function checkobj(checkProp) {
    if (myObj.hasOwnProperty(checkProp)) 
    
    return myObj [checkProp];

    return "Not Found";

A few things

No.1:
You are not supposed to create your own object here
Delete this

The goal is to create a function that works for any object.
Not just one you coded yourself.

No.2:
Reset the lesson because you deleted one of the parameters here

This is the correct parameters here

No.3:
You’re close here but you are supposed to check if obj has a property of checkProp.
Not my myObj

If the property exists then you are supposed to return the value from obj.
not myObj

1 Like

thanks very much. funny enough i just figured it out right after i sent the message.

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