Build a Wildlife Tracker - Step 11

Tell us what’s happening:

How is first log true and second one false, when both objects do not have the “habitat” . If we look at the object code, it does not have a habitat property but when logging out, it does give you true in first log. So question is, if there is some code “behind the scene” because tiger object do not have habitat property.

Your code so far

const tiger = {
  species: "Tiger",
  age: 5,
  isEndangered: true
};

const elephant = {
  species: "Elephant",
  age: 10,
  isEndangered: true
};

const getSpecies = (animal) => {
  return animal.species;
};

console.log(getSpecies(tiger));

const getAge = (animal) => {
  return animal.age;
};

console.log(getAge(tiger));

const addHabitat = (animal, habitat) => {
  animal.habitat = habitat;
  return animal;
};

console.log(addHabitat(tiger, "Rainforest"));

const updateAge = (animal, newAge) => {
  animal.age = newAge;
  return animal;
};

console.log(updateAge(elephant, 12));

const removeEndangeredStatus = (animal) => {
  delete animal.isEndangered;
  return animal;
};

console.log(removeEndangeredStatus(tiger));

// User Editable Region
function hasHabitat(animal){
  if(animal.hasOwnProperty("habitat")){
    return true
  }else{
    return false
  }
}

console.log(hasHabitat(tiger))
console.log(hasHabitat(elephant))
// User Editable Region

Your browser information:

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

Challenge Information:

Build a Wildlife Tracker - Step 11

GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/workshop-wildlife-tracker/6999b07c34c2cde21ee6e1d8.md at main · freeCodeCamp/freeCodeCamp · GitHub

Hi @mahassan,

You added the habitat property to Tiger.

Happy coding