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
return checkObj: "gift, pet, bed", "pony, kitten, sleigh";

// 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/104.0.5112.102 Safari/537.36 Edg/104.0.1293.63

Challenge: Basic JavaScript - Testing Objects for Properties

Link to the challenge:

Im about to lose it ive tried everything i wonder if its an issue with microsoft edge

Hello there.

Do you have a question?

If so, please edit your post to include it in the Tell us what’s happening section.

Learning to describe problems is hard, but it is an important part of learning how to code.

Also, the more information you give us, the more likely we are to be able to help.

The lesson is about hasOwnProperty but I don’t see you using it here. That is probably a red flag.

Edit : SOLUTION REMOVED

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

Hello! Use .hasOwnProperty to check if obj has given property and IF it HAS return its value, and if does not have it return “Not Found”

this is what i got so far
function checkObj(obj, checkProp) {
Obj({gift:“pony”, pet: “kitten”, bed: “sleigh”}, “gift”)
Obj({gift:“pony”, pet: “kitten”, bed: “sleigh”}, “pet”)
Obj({gift:“pony”, pet: “kitten”, bed: “sleigh”}, “house”)
Obj({city: “Seattle”}, “city”)
Obj({city: “Seattle”}, “district”)
Obj({pet: “kitten”, bed: “sleigh”}, “gift”)
myObj.hasOwnProperty(“gift”)
myObj.hasOwnProperty(“pet”)
myObj.hasOwnProperty(“house”)
myObj.hasOwnProperty(“city”)
myObj.hasOwnProperty(“district”)
myObj.hasOwnProperty(“gift”)
};

anyone? ive tried everything

how do i use the has own property

This looks like lot of hardcoding. You don’t need too much code here.

One big thing about functions is you usually are passing things to them as arguments and using them in the function with the parameters you have defined.

function checkObj(obj, checkProp) {

}

Here the function is named checkObj, and it has the parameters obj and checkProp. So far you have not used them at all in your function.

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

This is a function call which is how you pass values to your function. If you notice the first value is an object, the second value is a string. They will be given to your parameters for you to use in your function.

You can use hasOwnProperty method on an object, and pass it a string to test if that object has that property. And like the test says it will return a boolean of true or false depending on if the object has that property.

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
}
//I have this but it is not working and I can’t figure out what I’m missing

If you have a question about a specific challenge as it relates to your written code for that challenge, just click the Ask for Help button located on the challenge. It will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.