Solution is not provided

Solution is not provided
0

#1

Tell us what’s happening:
I don’t know what to do to past the test. Anyone can help?

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
  let count = 0;
    for(let items in obj){
    if(items.online){
      count++;
    }else{
      console.log("wowo");
    }
  }
  return count;
  // change code above this line
}

console.log(countOnline(users));

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


#2

What do the failing tests say?


#3

Hi siuhangw,

In your for loop console.log what “items” is and then that should help you continue with what you need to change.


#4

the in operator is handing you over the keys of the object (the names of the users in this case), but what you want is the actual user, so you need to look the user up in the users object like so:

if(users[items].online){
   count++;
}

#6

Thanks a-hariti. You saved my life


#7

Thanks JohnAyling. Problem solved.