Tell us what’s happening:
I can’t figure out what I am doing wrong. help please!!!
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) {
// change code below this line
for (let i = 0; i < users.length; i++) {
if (user.hasOwnProperty(isEveryoneHere)) {
return true;
} else {
return false;
}
// change code above this line
}
console.log(isEveryoneHere(users));
isEveryoneHere
is the name of that function. No object you’re testing has a property called that (there are two possible properties, age
and online
).
The second issue is that this is an object (users
) that you’re looping over. You can’t use a for loop the way you’re doing, because users
does not have a length
property: it’s not an array.
1 Like
Besides what @DanCouper said you have a minor TypeError in your code. You forgot to add the closing bracket for isEveryonHere(obj) function. Here, I have fixed the code for you but you need to correct your logic as mentioned by @DanCouper which is you are comparing the wrong property name i.e. ‘isEveryoneHere’. You need to change it to the names of the property i.e. ‘Alan’, ‘Jeff’, ‘Sarah’, ‘Ryan’. Also, you don’t need to use the for loop as you don’t require to iterate over the users object explicitly as the function ‘isEveryoneHere’ is doing that for you.
So, now your code should look like this:
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) {
// change code below this line
if (users.hasOwnProperty('Alan','Jeff','Sarah','Ryan')) {
return true;
} else {
return false;
}
// change code above this line
}
console.log(isEveryoneHere(users));
Hope it helps.