I cant make the countOnline function work

Tell us what’s happening:

i have followed the hint instructions and i cant still get the code to run

Your code so far


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

Your browser information:

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

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

Link to the challenge:

for (let user in usersObj) {

Are you sure you are suppose to write it like that?

In this challenge you don’t need to have function call included, it’s actually what makes test confused. Remove console.log(countOnline(usersObj)) and tests should pass.

2 Likes