Tell us what’s happening:
I can’t seem to figure out the correct methods of properly doing this loop.
Here’s how my mind is processing it:
It needs an if to determine if online is true . I pass the argument plus the iterated user and the online key to it using dot notation.
If this equals true it should then push that user into my num array. Once complete with the loop it can then return the .length of num which would be the number of people that were added to the array (online).
Why does this not work though?
Thank you
Your code so far
function countOnline(usersObj) {
// Only change code below this line
let num = [];
for (let user in usersObj) {
if (usersObj.user.online == true) {
num.push(user);
}
}
return num.length;
// Only change code above this line
}
Your browser information:
User Agent is: Mozilla/5.0 (iPhone; CPU iPhone OS 13_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0 EdgiOS/45.9.10 Mobile/15E148 Safari/605.1.15.
Challenge: Iterate Through the Keys of an Object with a for…in Statement
Link to the challenge: