In this challenge how are we defining the variable ?
I understand we are using `for (let user in users)’ to define the variable technically. But how does the code know that “user” is Alan, Jeff, Sarah, and Ryan specifically? Is it because that is the only property in the first level object? Thanks for any help!
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
var counter = 0;
for (var user in obj) {
if (obj[user]["online"] === true) {
counter++
}
// change code above this line
} return counter;
}
// change code above this line
console.log(countOnline(users));