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

Tell us what’s happening:

Unfortunately, my code is not passing the appropriate test to get the respective counts that I need. Do I have to make another for/in statement for false statements?
My results read this:

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

Your code so far


function countOnline(usersObj) {
// Only change code below this line
let user = {
Alan: {
online: false
},
Jeff: {
online: true
},
Sarah: {
online: false
},


};
function countOnline(usersObj) {
let online = 0;
for(let user in usersObj) {
  if(usersObj[user].online === false) {
   online++;
  }
}
return online;
}

// 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/81.0.4044.113 Safari/537.36.

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

Link to the challenge:

I think you’re counting offline users here.

Secondly, if condition expects boolean true or false, so these two will have exactly the same effect:

if (user.online === true) {}
// Same as:
if (user.online) {}

you have a function definition inside a function definition

you need to remove one of the two, or the inner one is never being called and the outer one doesn’t have a return statement

1 Like

Hello ieahleen, thank you for your feedback. Which function definition do I have to remove?

Thank you,

DJ

the one you wrote, as the other one is outside the part where the comments say you can change