Hi, all
I have a problem with Iterate Through the Keys of an Object with a for…in Statement | challenge.
First, this is my code :
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
// Create var called 'i' to start count online users from 0
let i = 0;
// use for to display all key for any obj come from function argument
for (let user in obj) {
// small condition to compare online key with his content
if(obj[user]['online'] == true) {
return i++
}
}
// change code above this line
}
console.log(countOnline(users));
I tried to explain my answer in the comments above and give you some information about how i think of it but, it’s return 0 ? and i don’t know why ??
Thanks for spending your time to help me