From f4353999e3e3dff5142a4159938fc5d8623a6cad Mon Sep 17 00:00:00 2001 From: Ryan Bowlen Date: Mon, 15 Oct 2018 17:04:14 -0500 Subject: [PATCH] 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. --- ...bject-with-a-for...in-statement.english.md | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/-iterate-through-the-keys-of-an-object-with-a-for...in-statement.english.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/-iterate-through-the-keys-of-an-object-with-a-for...in-statement.english.md index 172a2a8a5a..ce8bfdb5bd 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/-iterate-through-the-keys-of-an-object-with-a-for...in-statement.english.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/-iterate-through-the-keys-of-an-object-with-a-for...in-statement.english.md @@ -75,6 +75,35 @@ console.log(countOnline(users));
```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)); ```