Code works but fails tests

Tell us what’s happening:
Describe your issue in detail here.

  **Your code so far**

const users = {
Alan: {
  online: false
},
Jeff: {
  online: true
},
Sarah: {
  online: false
}
};

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

console.log(countOnline(users));
  **Your browser information:**

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36

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

Link to the challenge:

Hello there.

Do you have a question?

If so, please edit your post to include it in the Tell us what’s happening section.

Learning to describe problems is hard, but it is an important part of learning how to code.

Also, the more information you give us, the more likely we are to be able to help.


Why are you redefining the function parameter usersObj based upon the global variable users? Your code should not reference the global object at all.

2 Likes

I think you may have switched users and usersObj. If you switch them around in both places in the code, your code will pass.

1 Like

Thank you. This worked.

Thank you for your insight. Appreciated