Advertisement
darkmavis1980

Untitled

Jun 17th, 2019
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let users = {
  2.   Alan: {
  3.     age: 27,
  4.     online: false
  5.   },
  6.   Jeff: {
  7.     age: 32,
  8.     online: true
  9.   },
  10.   Sarah: {
  11.     age: 48,
  12.     online: false
  13.   },
  14.   Ryan: {
  15.     age: 19,
  16.     online: true
  17.   }
  18. };
  19.  
  20. function countOnline(obj) {
  21.     let count = 0;
  22.   for (let user in obj) {
  23.     if (obj[user].online) {
  24.       count++;
  25.     }
  26.   }
  27. return count;
  28. }
  29.  
  30. console.log(countOnline(users));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement