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

Tell us what’s happening:
guys i need help with this,I am stuck

Your code so far


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

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

Your browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0.

Challenge: Testing Objects for Properties

Link to the challenge:

Hey @ser1!
Welcome to FCC’s Forum.


Sorry, i don’t know. i just want to greet you.

Hi @ser1,

you have created your own object myObj, which is not what the challenge asks (or is about). The object to check will be provided as a function argument, so you don’t need to define one yourself.

The task is then to check if a certain property (checkProp - the second function argument) is a property on the given obj.

still doesn’t pass and i have tried several methods ,can you please take a screenshort or send me the code

why have you added the object in your code?

The first thing you’d have to do is delete that object myObj you’ve created. Then just run the function and at the beginning, see what’s passed to the function:

function checkObj(obj,checkProp) {
// Only change code below this line

  console.log(obj);

// Only change code above this line
}

That should show you why you don’t need to create your own object.

I am new to coding,And i was saw the example

I am new to coding ,now I am lost bcoz what you are saying is different from the example

your function is passed an object, obj, as such you don’t need to create an object

the function when called already has the object, example: checkObj({city: "Seattle"}, "city")

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

i am lost bro and im falling behind fix what needs to be fixed so that i can proceed to next challenge

bro thnx for the feedback but Iam running out of time please send me the code i will run it from here.

no, sorry, here in the forum we don’t share solutions.
You are not obligated to do the challenges, you can go to next one if you don’t like this one.

I’m trying to give you hints on how to pass the challenge, which boils down to: you are not testing the object you are given through the function parameter obj

Hey @ser1, firstly their is no need to panic. Read the instructions given for solving the problem carefully. If you still haven’t deleted the object myObj you have to do that then. Next, just use the if-else statements you have used but with the checkObj function arguments which are obj and checkProp respectively.

can you please send me the code because still it doesnt pass and i`m on 99%

Hi @ser1!

As mentioned earlier by @ilenia the challenges are technically optional for the certificates. The forum does not encourage sharing solutions but rather guiding you to the right solution.

If you want to post your updated code we can help you from there.

var myObj = {

gift ="pony",

pet = "kitten",

bed = "sleigh",

city ="Seattle"

};

if (myObj.hasOwnProperty(checkProp)) {

return obj[checkProp];

} else {

return "Not Found";

}

checkObj()

Have you tried deleting myobj that you created and just having an if else statement with obj and checkProp?

Also you don’t need to add the function call at the end for the test to pass.

Delete this function call

like these?

if (myObj.hasOwnProperty(checkProp)) {

return obj[checkProp];

} else {

return "Not Found";

}

You are so close but there is still this

Only use obj and checkprop

if (Obj.hasOwnProperty(checkProp)) {

return obj[checkProp];

} else {

return "Not Found";

}