Can someone help?I dont know how to do this?

Tell us what’s happening:

Your code so far


function countOnline(obj) {
// Only change code below this line
let result = 0;
for (let user in obj) {
if (obj[user].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/85.0.4183.83 Safari/537.36.

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

Link to the challenge:

@Jla you need to use a for…in statement within this function like this:

for (let user in users) {
  console.log(user);
}

then loop through the users object passed into the function

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

and return the number of users whose online property is set to true.

equivalent of a loop:

for (let user in obj) {
  if (obj[user].online === true) {
    //code
  }
}

this is a simple counter:

result++;