Iterate Through the Keys of an Object with a Statement two

Where is it not work?

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 b=[users][online];
let userOne = 0;
for (userOne in obj) {
if ( === true){
return ++userOne;}

return userOne;
// change code above this line


**Your browser information:**

User Agent is: `Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 YaBrowser/ Yowser/2.5 Safari/537.36`.

**Link to the challenge:**

This doesn’t have sense- what you want to do with this? You don’t even use b again

You can’t use the same variable as a counter and as an iterabile variable

What does the for in loop gives you? Do you know what values the iterated variables give?

If you use a return statement inside a loop, the return statement will break out of the function all together - you can’t use the return statement to update a variable if you need to do it many times

Okay, let’s start at the beginning. We should break the challenge down into easy-to-understand steps so that we can come up with an easy to implement solution.

So here are our steps:

  1. Create a variable to keep track of our online users (should start at 0).
  2. Use a for/in loop to iterate through the array.
  3. Check if the “online” property is true.
  4. If the last step is true then add it to our variable.
  5. Return the variable when the loop has finished.

Try to work on each step individually and in order. When you have one step done, move onto the next. If you get stuck, google what it is that you are stuck on and look for a solution that may help :slight_smile:

Thank you for yuor advice.