Check if an Object has a Property- help

Check if an Object has a Property- help
0.0 0

#1

Tell us what’s happening:

I can’t figure out what I am doing wrong. help please!!!

Your code so far


let users = {
  Alan: {
    age: 27,
    online: true
  },
  Jeff: {
    age: 32,
    online: true
  },
  Sarah: {
    age: 48,
    online: true
  },
  Ryan: {
    age: 19,
    online: true
  }
};

function isEveryoneHere(obj) {
  // change code below this line

for (let i = 0; i < users.length; i++) {
  if (user.hasOwnProperty(isEveryoneHere)) {
    return true;
} else {
  return false;
}
  // change code above this line
}

console.log(isEveryoneHere(users));

#2

isEveryoneHere is the name of that function. No object you’re testing has a property called that (there are two possible properties, age and online).

The second issue is that this is an object (users) that you’re looping over. You can’t use a for loop the way you’re doing, because users does not have a length property: it’s not an array.