Hey, I initially tried solving this with the code in the bottom of this post but it wouldn’t work.
It seems odd that I’d need to rewrite each like this
if ("Alan" in users &&
"Jeff" in users &&
"Sarah" in users &&
"Ryan" in users)
{
return true;
}
return false;`
or this
if (
obj.hasOwnProperty("Alan") &&
obj.hasOwnProperty("Jeff") &&
obj.hasOwnProperty("Sarah") &&
obj.hasOwnProperty("Ryan")
) {
return true;
}
return false; `
Is there a way to generally not have to re write obj.hasOwnProperty
or in users
? Thanks
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) {
// Only change code below this line
if ('Alan' && 'Jeff' && 'Sarah' && 'Ryan' in users) {
return true;
} else {
return false;
}
// Only change code above this line
}
console.log(isEveryoneHere(users));
Challenge: Check if an Object has a Property
Link to the challenge: