Basic JavaScript - Testing Objects for Properties

Tell us what’s happening:
Describe your issue in detail here.

Your code so far
help

function checkObj(obj, checkProp) {
  // Only change code below this line
  return "Not Found";
  // 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/117.0.0.0 Safari/537.36

Challenge: Basic JavaScript - Testing Objects for Properties

Link to the challenge:

Can you explain what it is that you’re struggling to understand about this challenge please? The better you can describe your issue, the easier it is for us to understand how best to help you.

1 Like
  • Passed:checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "gift") should return the string pony.

  • Passed:checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "pet") should return the string kitten.

  • Failed:checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "house") should return the string Not Found.

  • Passed:checkObj({city: "Seattle"}, "city") should return the string Seattle.

  • Failed:checkObj({city: "Seattle"}, "district") should return the string Not Found.

  • Failed:checkObj({pet: "kitten", bed: "sleigh"}, "gift") should return the string Not Found.
    i cant return not found

You are only returning “Not Found” in the function. You arent doing everything the directions ask for.

" test if the object passed to the function parameter obj contains the specific property passed to the function parameter checkProp . If the property passed to checkProp is found on obj , return that property’s value. If not, return Not Found ."

You only added code for the last sentence you still need to do everything before that.

i still don’t get it

return obj[checkProp];

Can you be more specific?

Your first goal is to write code that " If the property passed to checkProp is found on obj" an easy way to start this is making an if statement

Next “return that property’s value” if the above is true then you are going to return the property value

Then " if not, return Not Found ." Here you return Not found in a else statement or just add it after the if statement.

If you need to know how to set up an if statement you can see it here

Hint: Read carefully and understand the instruction.

" test if the object passed to the function parameter obj contains the specific property passed to the function parameter checkProp . If the property passed to checkProp is found on obj , return that property’s value. If not, return Not Found ."

try using if statement to solve this problem.

here is my solution
mod edit: removed solution

your answer is correct if you are just returning the property of checkProp but you have to check first if a property on a given object exists or no.

solution for checking if the property exists on a given object:

@IamAaron20

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.

thanks so much i have been struggling so much thanks

Noted on this. Thank you.

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