Users with online set to true

I have a problem with this challenge. Pls help
I need to return users which have online property set to true.

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) {
}

console.log(countOnline(users));

Hello Slaven!

Which challenge are you working on? Can you provide a link to the page?

Also, what exactly are you having trouble with? What is the output you are getting?

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

I tried using this, but it does not work.
let count = 0;
for(let user in obj) {
if(user.online === true) {
count += 1;
}
}
return count;

Of course it does not work. What is obj ? First you declare you users object like ‘users’, and you are looping obj. Change that. Second what is user in the loop. DId you log it?
Try that:

let count = 0;
for(let user in users) {
if(users[user].online === true) {
count += 1;
}
}

This why i had that ‘obj’. My problem was that I forgot I have to reference obj in the contidion.
Thanks
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) {
let count = 0;
for(let user in obj) {
if(obj[user].online === true) {
count += 1;
}
}
return count;
}
console.log(countOnline(users));

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.

markdown_Forums