Tell us what’s happening:
Unfortunately, my code is not passing the appropriate test to get the respective counts that I need. Do I have to make another for/in statement for false statements?
My results read this:
The function countOnline should return 1 when the object
{ Alan: { online: false }, Jeff: { online: true }, Sarah: { online: false } }
is passed to it.
The function countOnline should return 2 when the object
{ Alan: { online: true }, Jeff: { online: false }, Sarah: { online: true } }
is passed to it.
The function countOnline should return 0 when the object
{ Alan: { online: false }, Jeff: { online: false }, Sarah: { online: false } }
is passed to it
Your code so far
function countOnline(usersObj) {
// Only change code below this line
let user = {
Alan: {
online: false
},
Jeff: {
online: true
},
Sarah: {
online: false
},
};
function countOnline(usersObj) {
let online = 0;
for(let user in usersObj) {
if(usersObj[user].online === false) {
online++;
}
}
return online;
}
// Only change code above this line
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.113 Safari/537.36
.
Challenge: Iterate Through the Keys of an Object with a for…in Statement
Link to the challenge: