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

Tell us what’s happening:

Hi all, whats wrong in my code so far? Thanks.

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 onlinePeople=[];
for (let user in obj) {
  if (user.online == true){
    onlinePeople.push(user);
  }
  else {
    continue;
  }
}
return onlinePeople.length;
  // change code above this line
}

console.log(countOnline(users));

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 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

user is a string so it doesn’t have online property

yepp i’ve just changed my code as below than it solved, appreciated it :star_struck:

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 onlinePeople=[];
for (let user in obj) {
if (users[user].online == true){
onlinePeople.push(user);
}
else {
continue;
}
}
return onlinePeople.length;
// change code above this line
}

console.log(countOnline(users));