Hello!
Below is my solution for this challenge.
But I have some questions.
- Instead of return, I used console.log(counter).
Result has to be “2”, but if I use console.log, it was “2, undefined”.
Why is it so?? - I understand “user” is variable that has to be in the bracket.
and “online” is specific root that you can use both bracket and dot notation.
but how about “obj”? I try using bracket and it failed to read. Why is it so?
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 counter =0;
for (let user in obj){
if(obj[user].online){
counter++
}
} return counter;
// change code above this line
}
console.log(countOnline(users));