Iterate Through the Keys of an Object with a for...in Statement

const users = {
Alan: {
online: false
},
Jeff: {
online: true
},
Sarah: {
online: false
}
}

function countOnline(allUsers) {
// Only change code below this line
let result = 0;
for (let users in allUsers) {
if (allUsers[users].online === true) {
result++;
}
}
return result;
// Only change code above this line

}

console.log(countOnline(users));

Please Tell us what’s happening in your own words.

Learning to describe problems is hard, but it is an important part of learning how to code.

Also, the more you say, the more we can help!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.