Basic JavaScript - Testing Objects for Properties

Tell us what’s happening:
hey guys , i’ve been trying to solve this code for ages i really don’t understand how to do it , does anyone know if you should have multiple return statements for the 3 different codes in the instructions. i also tried making a ‘Things’ object that had all the propertys but that did’nt work either. Any help would be really appreciated.

Your code so far

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

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

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.5 Safari/605.1.15

Challenge: Basic JavaScript - Testing Objects for Properties

Link to the challenge:

You’re actually only returning 2 different options. its either the obj and property if it matches, or Not Found if it doesn’t. Do you remember how to check for true/false conditions ?

Do you mean like this ? , it still hasnt worked for me

function checkObj(obj, checkProp) {
  // Only change code below this line
  return "Not Found";
  
}
    let things = { 
      gift: "pony",
      pet: "kitten",
      bed: "sleigh",
      city: "Seattle"
    }

   if(things.hasOwnProperty("gift")) {
console.log("pony");
}else{
console.log("Not Found");
}

if(things.hasOwnProperty("pet")){ 
  console.log("kitten");
}else{
console.log("Not Found");
}

if(things.hasOwnProperty("city")){ 
  console.log("Seattle");
}else{
console.log("Not Found");
}

  // Only change code above this line

Unfortunately not quite. There’s no need to make a “things” variable.
Also, you can solve this test with a single if else statement.
lastly, you can use the “return” keyword instead of “console.log”

keep in mind, with hasOwnProperty(), you can pass in more than just strings

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