function countOnline(obj) {
// change code below this line
let onlineCount = 0;
for(let user in obj){
if(obj[user][‘online’]){
onlineCount++;
}
}
return onlineCount;
// change code above this line
}
But I wondered to know is there any way to accessing user without using obj?
Let me clear my question:
If I change the loop as below:
for(let user in obj){
if(user[‘online’]){
onlineCount++;
}
}
the function doesn’t work truly. It seems we can’t access user(inside for loop) in that way and I wonder to know is there any way to accessing user without using obj(inside for loop)?
when user is Alan that would give you Alan["online"], which doesn’t let you call anything, because Alan is a key of an object, so you need to use it to call datas from inside an object, on its own doesn’t do anything
In your case, obj is users becuase you have passed users as argument of the function, and so obj[user]["online"] is equivalent to users["Alan"]["online"].
it is a question of how to call datas from inside an object.