Why is my countOnline function not working I don't get it

Tell us what’s happening:

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


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36.

Link to the challenge:

The problem here is with the return statement.
When the interpreter finds the word return it returns the value and stops.

The same goes for return in a loop statement,
It runs only once => finds return => stops.

That’s not what it is wanted.

You want to return the value of count only after the for…in loop finishes looping the obj.

Fix that.

And also, do not forget to take off theconsole.log from the function call countOnline(users);

Thanks a million, my return statement was still in the for loop.

You’re welcome.

Good Luck & Happy Coding!