Problem in output

Tell us what’s happening:
I can’t seem to find the mistake in outputting result, I pass on
console.log(checkObj(“gift”));

but it results in NOT FOUND

Your code so far


function checkObj(Obj, checkProp) {

// Only change code below this line
var Obj = {
  gift: "pony",
  pet: "kitten",
  bed: "sleigh",
  city: "Seattle"
}
if (Obj.hasOwnProperty(checkProp)) {
  return Obj[checkProp];
}
else {
return "Not Found"}
}
// Only change code above this line
console.log(checkObj("gift"))


Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36.

Challenge: Testing Objects for Properties

Link to the challenge:

  • It looks like you changed the capitalization of obj to Obj. Don’t do that.
  • The object obj should be a parameter that is passed into the checkObj() function. You should not hardcode it.
  • The checkObj() function takes two parameters, not one. The tests show what parameters they will pass to the function.

Does this look better and i didn’t understand the third point

function checkObj(obj, checkProp) {

// Only change code below this line

// Only change code below this line

var obj = {

gift: "pony",

pet: "kitten",

bed: "sleigh",

city: "Seattle"

}

if (obj.hasOwnProperty(checkProp)) {

return obj[checkProp];

}

else {

return "Not Found"}

}

// Only change code above this line

console.log(checkObj("gift"));

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.

markdown_Forums

You fixed the capitalization of obj, but you are still not using the obj argument.
You should not be creating that object in your code. When the function is called it will be called with two arguments: an object and a string.

This is NOT how checkObj will be called.

Now this creates a problem for the obj and is exactly how it has been explained in the video, i must be wrong somewhere and could you show me the right way

var obj = {

gift: "pony",

pet: "kitten",

bed: "sleigh",

city: "Seattle"

}

function checkObj(checkProp) {

if (obj.hasOwnProperty(checkProp)) {

return obj[checkProp];

}

else {

return "Not Found"}

}

// Only change code above this line

console.log(checkObj("pet"));

The video is from an old version of the challenge. Turn it off and listen to what people are actually telling you.

I want to do exactly :grinning that but i am having a hard time understanding what you are actually telling me to do, How should i actually output the results of the function where i am being wrong and what is the right way to correct it.

Delete obj. Use the argument passed to your function.

look here, the function is defined with two parameters
so to test the function you also need to call it with two parameters

like checkObj({city: "Seattle"}, "city")

1 Like

thanks magical girl and arielleslie for your patience:)