Basic JavaScript - Testing Objects for Properties

Tell us what’s happening:
Describe your issue in detail here.
There are two tasks there which contradict each other . in one they want a gift and in other one they want the result not found someone please help.

Your code so far

//Setup
var myObj = {
  gift: "pony",
  pet: "kitten",
  bed: "sleigh",
  city: "Seattle",
};

function checkObj(obj, checkProp) {
  // Only change code below this line
  if (myObj.hasOwnProperty(checkProp) == true) {
    return myObj[checkProp];
  } else {
  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/116.0.0.0 Safari/537.36

Challenge: Basic JavaScript - Testing Objects for Properties

Link to the challenge:

replace myObj to obj in both lines

I think you may have got yourself confused when declaring the set up of the object being checked.

  1. instead of myObj.hasOwnProperty, it would be obj.hasOwnProperty, as this tests the object that FCC have created and passed in as the first argument to the function call behind the scenes for their tests

  2. You can remove the “== true”, as the hasOwnProperty returns a boolean anyway, so you do not have to explicitly check if true or false.

  3. As per point 1, you are checking the obj passed in by FCC behind the scenes, not the one you have manually declared, so you want to use obj here as well instead of myObj

Mod Edit: SOLUTION REMOVED

Hope this helps :slight_smile:

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.

1 Like

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