Able to get the correct output from the test cases but answer was not accepted

Tell us what’s happening:
I am confused why my solution is not accepted when it works for all the test cases mentioned. I tried modifying the usersObj property values for each test case, and was able to get the answer they expected.

  **Your code so far**

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

function countOnline(usersObj) {
// Only change code below this line
let onlineCount=0;
for (let userKey in usersObj){
  if(users[userKey].online===true){
    onlineCount+=1;
  }
}
return onlineCount;
// Only change code above this line
}
console.log(countOnline(users));
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36

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

Link to the challenge:

Here you are not using the function argument usersObj and instead directly referencing the global variable users. This will cause some of the tests to fail.

Thanks Jeremy! I didn’t realise I wasn’t using the parameter =/
Wew I spent a disproportionate time on this last night, appreciate your 2nd pair of eyes.

Yea, it’s like that sometimes.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.