Tell us what’s happening:
I’m doing the for in loop and I tested my code in Codepen and the result counts 0,1,2,3 as intended when I directly use “users” as the object literal instead of the parameter “usersObj”.
Although the the fcc console only accepts usersObj[names].online
**Your code so far**
const users = {
Alan: {
online: false
},
Jeff: {
online: true
},
Sarah: {
online: false
}
}
function countOnline(usersObj) {
// Only change code below this line
let i = 0;
for (let names in users) {
if(users[names].online === true) {
i++;
}
}
return i;
// Only change code above this line
}
console.log(countOnline(users));
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36
Challenge: Basic Data Structures - Iterate Through the Keys of an Object with a for…in Statement
Use argument for different objects.
Although I understand that the real world would only have one name per user that’s probably why I didn’t pay attention to the re-usability.
But I do understand the applicability of using the argument instead of the object name now.