Basic Dat Structures: Iterate Through the Keys of an Object with a for...in Statement

Tell us what’s happening:

my code is same as the hint answer. what is wrong

// running tests 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 // tests completed

Your code so far


function countOnline(usersObj) {
// 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
}

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.116 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

there is not an obj object around here, why are you using it?