Stuck on an exercise... Help!

Hi fellas.
The follow is the requirement of the exercise-
We’ve defined a function, countOnline ; use a for…in statement within this function to loop through the users in the users object and return the number of users whose online property is set to true .
I’ve tried everything but the value of the variable ‘i’ remains 0;
Please help.

Your code so far


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 i=0;
for(let user in obj){
if(user['online']==true){
i=i+1;
}
}
return i;
  // change code above this line
}

console.log(countOnline(users));

Your browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:66.0) Gecko/20100101 Firefox/66.0.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-data-structures/-iterate-through-the-keys-of-an-object-with-a-for---in-statement

Look at how for...in works carefully, and mayble play with it a little bit. What is “user” in each iteration of the loop?

Oooh! Thank you @ArielLeslie. :smiley: