Can quite figure this one out.. Can anyone tell me what I'm doing wrong..It's from the: Iterate Through the Keys of an Object with a for...in Statement challenge

let users = {// this was provided from here
  Alan: {
    age: 27,
    online: false
  },
  Jeff: {
    age: 32,
    online: true
  },
  Sarah: {
    age: 48,
    online: false
  },
  Ryan: {
    age: 19,
    online: true
  }
};
function countOnline(obj) {// this was provided to here
  // change code below this line..my changes
  let result = 0;
  for (let user in obj) {
    if (obj[user].online === true) {
      result++;
    }
  }
  return result;
  // change code above this line...my changes
}
console.log(countOnline(users));//this was provided

Below is the error I’m receiving:

The function

countOnline

should return

1

when the object

{ Alan: { online: false }, Jeff: { online: true }, Sarah: { online: false } }

is passed to it The function

countOnline

should return

2

when the object

{ Alan: { online: true }, Jeff: { online: false }, Sarah: { online: true } }

is passed to it The function

countOnline

should return

0

when the object

{ Alan: { online: false }, Jeff: { online: false }, Sarah: { online: false } }

is passed to it

Your code is working fine for me.

Hi Ed,

The only code I need to provide is:

let result = 0;
for (let user in obj) {
if (obj[user].online===true) {
result++;
}
}
return result;

Everything else was for reference to those that offered help…

That is weird… maybe it’s telling me to come back later…also can you attached what you pasted…I just want to check again what I’m doing

Hi Zimtech0,

My guess would be that your function parameter name (usersObj) is different than the variable being used inside the function (obj).

So either change the function parameter name or your variable inside.

function countOnline(obj) {
  // change code below this line
  let result = 0;
  for (let user in obj) {
    if (obj[user].online===true) {
      result++;
    }
  }
  return result;
  // change code above this line
}