For...In statement problem

Tell us what’s happening:
I have tried solving this problem however, nothing works. I’ve even inputted the solution and it still doesn’t work. it keeps saying object is undefined. Help please.

Your code so far


let users = {
Alan: {
  online: false
},
Jeff: {
  online: true
},
Sarah: {
  online: false
},
Ryan: {
  online: true
}
};
function countOnline(usersObj) {
// Only change code below this line
let result = 0;
for (let user in obj) {
if (user[obj].online === true) {
  result++;
}
}
return result;
// Only 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/80.0.3987.132 Safari/537.36.

Challenge: Iterate Through the Keys of an Object with a for…in Statement

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

for (let user in obj) {
    if (user[obj].online === true) { // here is your problem
       // user is a key of obj,  ie obj[user]
       result++;

// object = {user: {online: true}}
// for user in object
//    object[user].online == true

The above comment fixes part of this. The other part is that countOnline has a parameter called usersObj, and you’re referring to it as obj.
I don’t wanna be that guy, but the error was quite descriptive, obj was literally not defined, ie you never defined it. It didn’t exist. Don’t forget the error messages are there to help you, it’s not supposed to be some alien language.

Hello try this ,Hope it help,

let users = {
  Alan: {
    age: 21,
    online: false
  },
  Jeff: {
    age: 31,
    online: true
  },
  Sarah: {
    age: 41,
    online: false
  },
  Ryan: {
    age: 19,
    online: true
  }
};
function countOnline(obj) {
  let result = 0;
  for (let user in obj) {
    if (obj[user].online === true) {
      result++;
    }
  }
  return result;
}
console.log(countOnline(users));