Help with Check if an Object has a Property

Tell us what’s happening:
no matter what code i put in i keep getting
" The users object should not be accessed directly"

  **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(userObj) {
// Only change code below this line
let everyone = ["Alan", "Jeff", "Sarah", "Ryan"];

for (let i = 0; i < eveyone.length; i += 1) {
  let student = everyone[i];
  if (users.hasOwnProperty(student) === false) {
    return false;
  }
}
return true;
// Only change code above this line
}

console.log(isEveryoneHere(users));
  **Your browser information:**

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

Challenge: Check if an Object has a Property

Link to the challenge:

The function has an argument.

Here you are ignoring the function argument and directly accessing the global variable. This makes your function far less flexible, and the instructions are telling you not to do this.

users is a global variable. You need to use the same argument as the function >> userObj

The reason for this is because in the console.log you are running the function with users which replaces the function argument from userObjto users hence it will return true.

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