Add solution to Challenge (#19369)

Added a solution to "Iterate Through the Keys of an Object with a for...in Statement"'s "Get a Hint" documentation.
This commit is contained in:
Ryan Bowlen
2018-10-15 17:04:14 -05:00
committed by Aditya
parent ac383c7632
commit f4353999e3

View File

@ -75,6 +75,35 @@ console.log(countOnline(users));
<section id='solution'>
```js
// solution required
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) {
let online = 0;
for(let user in obj){
if(obj[user].online == true) {
online += 1;
}
}
return online;
}
console.log(countOnline(users));
```
</section>