Check if an object has a property - First test not reliable

Tell us what’s happening:
I just want to report that the first test in this challenge fails if a variable’s name contains the word “users”, even if the variable doesn’t contain the users object.

The following code fails with "The users object should not be accessed directly"

function isEveryoneHere(userObj) {
// Only change code below this line
let usersList = ["Alan", "Jeff", "Sarah", "Ryan"];
for (let i = 0; i < usersList.length; i++) {
  if (userObj.hasOwnProperty(usersList[i]) == false) {
    return false;
  }
}
return true;

// Only change code above this line
}

console.log(isEveryoneHere(users));

However, if you remove the word “users” from the variable name, then the test passes

function isEveryoneHere(userObj) {
// Only change code below this line
let List = ["Alan", "Jeff", "Sarah", "Ryan"];
for (let i = 0; i < List.length; i++) {
  if (userObj.hasOwnProperty(List[i]) == false) {
    return false;
  }
}
return true;

// Only change code above this line
}

console.log(isEveryoneHere(users));

Challenge: Check if an Object has a Property

Link to the challenge:

Ya, sometimes the tests get fooled and little things like this happen.

Did you know that there is a way to solve this challenge by creating an array of names like you did but without actually assigning it a variable name? This would bypass the issue you are having completely. Instead of using a for loop to go through the array you could use an array method to check every item in the array. Check out solution 2 in the hints.

1 Like

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