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.
pull/19381/head
Ryan Bowlen 2018-10-15 17:04:14 -05:00 committed by Aditya
parent ac383c7632
commit f4353999e3
1 changed files with 30 additions and 1 deletions

View File

@ -75,6 +75,35 @@ console.log(countOnline(users));
<section id='solution'> <section id='solution'>
```js ```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> </section>