I am doing a freecodecamp challenge and I am being asked to finish writing a function that returns true if the object passed contains all four names: 'Alan' 'Jeff' 'Ryan' 'Sarah'. an Object is defined earlier, containing the data :
let users = {
Alan: {
age: 27,
online: true
},
Jeff: {
age: 32,
online: true
},
etc. the function begins like this
function isEveryoneHere(userObj) {}
and I have this written as my completed function, in which I am able to return all 4 names:
for (const property in userObj) {
if (userObj) {
return userObj.hasOwnProperty(property)
}
But I am still being told that I am not meeting the criteria of the challenge. Any pointers or tips of advice?
edit: Error Message The users object should not be accessed directly
Passed The users object should only contain the keys Alan, Jeff, Sarah, and Ryan
Passed The function isEveryoneHere should return true if Alan, Jeff, Sarah, and Ryan are properties on the object passed to it.
The function isEveryoneHere should return false if Alan is not a property on the object passed to it.
The function isEveryoneHere should return false if Jeff is not a property on the object passed to it.
The function isEveryoneHere should return false if Sarah is not a property on the object passed to it.
The function isEveryoneHere should return false if Ryan is not a property on the object passed to it
edit:
this is how they solved it
function isEveryoneHere(userObj) {
if (
userObj.hasOwnProperty("Alan") &&
userObj.hasOwnProperty("Jeff") &&
userObj.hasOwnProperty("Sarah") &&
userObj.hasOwnProperty("Ryan")
) {
return true;
}
return false;
}