Iterate Through the Keys of an Object with a for...in Statement ughs

Tell us what’s happening:

keeps coming up with this error:

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```
ive sat here so long with this one code i decided to see if someone might help

im personally tired of trying. lol.

**Your code so far**
      
```js

let users = {
Alan: {
  age: 27,
  online: false
},
Jeff: {
  age: 32,
  online: true
},
Sarah: {
  age: 48,
  online:false
},
Ryan: {
  age: 19,
  online: true
}
};

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


Your browser information:

User Agent is: Mozilla/5.0 (X11; CrOS x86_64 12499.66.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.106 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

the two statements don’t really match:

for (let **user** in obj)

and

if (obj[**users**].online === true)

Outlined with ** for better visibility.
It’s just a matter of syntax, you’re close to the solution.
Hope this helps :+1:

1 Like

tyvm i sat there for another few minutes and relooked at my code via the guide for the code and realized what i did wrong. lol. amazing how that happens when you aint thinking. ty again.