I don't know how to solve, I have tried many times

This isn’t quite right. hasOwnProperty is a method (or function if you prefer). That’s not how you invoke a method.

This worked but I don’t know how.

function checkObj(obj, checkProp){
return obj[checkProp]|| "Not Found";
  // Only change code above this line

I think we only had to write a function and I was declaring object as well as calling a function that’s why it wasn’t working.

This is not good :slight_smile: You should always understand the code you are writing. You only have two lines of code. You should be able to explain what each line does and why you need it. If you can’t do that then you didn’t really pass the challenge. I would erase what you have and start over again using code that you understand.

yeah I agree, I make sure I understand what’s going on that’s why I spent a lot of time on this one.

Also, since the challenge introduces the hasOwnProperty method I think it is a safe bet that you should use that method in your solution. Granted, as you found out, you don’t technically need to use it, but in the real world there are use cases where you need to use it, the challenge just doesn’t go into that much detail. Also, the tests aren’t quite as strict as they could be in order to require that you use hasOwnProperty (but they could be).

Regardless, use it in your solution since that is the point of this challenge.

Hi @saimanaz828, I can see 2 small mistakes due to which your code is not working.

I will explain where you have gone wrong and will give the correct solution at the end.

Line 7

you have used square brackets “[ ]” instead of parenthesis “( )” to call a function.

Line 9

var check = object.hasOwnProperty[(checkProp);
you have used square brackets “[ ]” instead of parenthesis “( )” for the method “hasOwnProperty”

Line 10 can also be written as
return (check? object[checkProp]: "Not Found");
No need to compare with boolean (true or false), there is concept of truthy and falsy
you can refer this MDN link Truthy - MDN Web Docs Glossary: Definitions of Web-related terms | MDN

Below is the working solution

const object= {
 gift: "pony", 
 pet: "kitten", 
 bed: "sleigh",
 city: "Seattle",
function checkObj(checkProp){
var check = object.hasOwnProperty(checkProp);
return (check? object[checkProp]: "Not Found");
 // Only change code above this line

Hope this helps :wink:

HI @srikargunnam !

Welcome to the forum!

We don’t encourage users to share full solutions on the forum.
Instead it is best to provide hints so the user can solve it on their own.

But while we are here :grinning:
Two things.

We want to encourage users to create functions that work for any object.
Not one hardcoded for these tests.
You shouldn’t need to create this at all

we don’t want to change the function signature here

we do want to work with the function signature they provided in the challenge which is this

Hi @jwilkins.oboe,

My mistake!

I thought i was just helping him understand why the particular code which he posted in the forum is not working, It was not my intention to give a entire solution to the answer, i just copy pasted his solution with modifications.

I will not repeat this again.

Happy coding :wink:

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