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
parent
ac383c7632
commit
f4353999e3
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue