Tell us what’s happening
I passed all criteria except for this:
“The users object should not be accessed directly”. Not sure what I did wrong here. Could someone please explain?
Link to challenge:
Code:
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
if ('Alan' in users && 'Jeff' in users && 'Sarah' in users && 'Ryan' in users) {
return true;
} else {
return false;
}
// Only change code above this line
}
console.log(isEveryoneHere(users));
The point of using a function is reusability - if you access “users” directly, why even go through the trouble of writing all that fluff around? It would be pointless.
However if you want to check a bunch of objects, you can write one function and give each object as argument to get a result.
Also on the note of results: if the statement in the “if (stuff)” evaluates as true, it will go into the if-branch, if not, into the else branch.
Meaning: if (statement) {return true} else {return false} is the same is return statement