Tell us what’s happening:
Debug output shows each key in the users object property being passed correctly “true or false” tested with line “console.log(users[bar].online);”.
Return of online count = true by foo is correct.
Debugged with test data that fails, debug console.log() output shows it returns the correct count of users online.
After debugging and not coming up with a passed test, I looked at the hints and my logic is the same. Perhaps either the exercise has a bug or I need a second set of eyes on this.
Please take a look at my code below and confirm it is correct and should work.
**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 foo = 0;
for (let bar in users) {
console.log(users[bar].online);
if (users[bar].online === true){
foo++;
}
}
return foo;
// Only change code above this line
}
console.log(countOnline(users));
**Your browser information:**
User Agent is: Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:99.0) Gecko/20100101 Firefox/99.0
Challenge: Iterate Through the Keys of an Object with a for…in Statement
Link to the challenge: