Iterating using object key

Tell us what’s happening:
Need help please, i am struggling to solve this problem. What was the right answer.
This is my code let result = 0; for (let user in users) { if (users[user].online) { result++; } } return result;

Your code so far


function countOnline(usersObj) {
// Only change code below this line
let result = 0;

for (let user in users) {
  if (users[user].online) {
    result++;
  }
}
return result;


  // Only change code above this line
}

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:74.0) Gecko/20100101 Firefox/74.0.

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

Link to the challenge:

Hi there,

The reason why it isn’t working is because the argument in the function is usersObj
so you need to iterate through usersObj instead of users

Good Luck :smiley:

2 Likes

Thanks Curtis for your response.
I have tried tochange the code, but still not working.

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