Iterate Through the Keys of an Object with a for...in Statement - not passing

Iterate Through the Keys of an Object with a for...in Statement - not passing
0

#1

Tell us what’s happening:

What Im missing?? My code do exactly what is asked:
use a for…in statement within this function to loop through the users in the users object and return the number of users whose online property is set to true.

But does not validate, even Im looping with for… in and result is 2 as should be ;(

Your code so far


let users = {
  Alan: {
    age: 27,
    online: false
  },
  Jeff: {
    age: 32,
    online: true
  },
  Sarah: {
    age: 48,
    online: false
  },
  Ryan: {
    age: 19,
    online: true
  }
};

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

console.log(countOnline(users));

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1.2 Safari/605.1.15.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-data-structures/-iterate-through-the-keys-of-an-object-with-a-for---in-statement


#2

Make sure you are declaring your variable with keywords like let.

The log tells you that count is not defined.


#3

Thanks. Im totally blind. :slight_smile: