Iterate Through the Keys of an Object with a for...in Statement returns 0 every time

Iterate Through the Keys of an Object with a for...in Statement returns 0 every time
0

#1

Tell us what’s happening:
Why wont this work?

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  u in obj)
{
  if(u.online == true)
  {
    i ++;
  }
}
return i;
  // change code above this line
}

console.log(countOnline(users));

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36.

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


#2
for(let  u in obj)
{
  if(u.online == true)
  {
    i ++;
  }
}

In for-in loops, the u variable will always contain the object’s key, not the actual object value. So here the u variable will take the values 'Alan', 'Jeff', etc., not their corresponding objects