Why doesn’t usersObj.user.online not work, but usersObj[user].online does?
Your code so far
function countOnline(usersObj) {
let usersOnline = 0;
for (let user in usersObj){
if(usersObj[user].online === true){ // usersObj.user.online won't work
usersOnline++;
}
}
return usersOnline;
}
Your browser information:
User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:71.0) Gecko/20100101 Firefox/71.0.
Challenge: Iterate Through the Keys of an Object with a for…in Statement
In other words in:
for (let user in userObj) {…} , I’m getting let user = “Alan”. I can’t use userObj . “Alan”. online; doesn’t work. I’ll have to use bracket notation for strings. Otherwise use dot notation like in the tutorial following this one.