Basic Data Structures - Iterate Through the Keys of an Object with a for...in Statement

Tell us what’s happening:
Describe your issue in detail here.
In that code, am only returning 1, so
how should make the The function countOnline to return 2 and ‘0’ as the hint message says?
Your code so far

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

function countOnline(allUsers) {
  // Only change code below this line
let result = 0;
  for (let user in allUsers) {
    if (allUsers[user].online === true) {
      result++;
    }
  }
  return result;
  // 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/113.0.0.0 Safari/537.36

Challenge: Basic Data Structures - Iterate Through the Keys of an Object with a for…in Statement

Link to the challenge:

This part is calling your function with the object users from the top of your code and logging it to the console, which only has 1 user online. If you run your code the test will pass other objects that have 2 or 0 users online to your function. Try running the test, your code should pass.

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