function countOnline(obj) {
// change code below this line
// let b=[users][online];
let userOne = 0;
for (userOne in obj) {
if ( users.online === true){
return ++userOne;}
}
return userOne;
// change code above this line
}
console.log(countOnline(users));
**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/19.4.2.702 Yowser/2.5 Safari/537.36`.
**Link to the challenge:**
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-data-structures/-iterate-through-the-keys-of-an-object-with-a-for---in-statement
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:
Create a variable to keep track of our online users (should start at 0).
Use a for/in loop to iterate through the array.
Check if the “online” property is true.
If the last step is true then add it to our variable.
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