Anyone here know why this code is not working?

let users = {
Alan: {
age: 27,
online: false
},
Jeff: {
age: 32,
online: true
},
Sarah: {
age: 48,
online: false
},
Ryan: {
age: 19,
online: true
}
};

function countOnline(obj) {
// change code below this line
let onlineUsers = 0;
for (let user in users) {
if (user.online) {
onlineUsers += 1;
};
};
return onlineUsers;
// change code above this line
}

console.log(countOnline(users));
You already invited:

Cassava

Upvotes from:

Log the value of user to be sure it is the object and not the key
You should use users[user].online

Daryl k

Upvotes from:

you should use let user in obj
Instead of let user in users loop

If you wanna answer this question please Login or Register