Tell us what’s happening:
Hello, I have written code with the user having their respective online property value but I am not getting the appropriate return when the objects are passed through.
The function countOnline should return 2 when the object
{ Alan: { online: true }, Jeff: { online: false }, Sarah: { online: true } }
is passed to it
Your code so far
function countOnline(usersObj) {
// Only change code below this line
let user = {
Alan: {
online: true
},
Jeff: {
online: false
},
Sarah: {
online: true
},
};
{
let online = 0;
for(let user in usersObj) {
if(user.online === true)
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.129 Safari/537.36
.
Challenge: Iterate Through the Keys of an Object with a for…in Statement
Link to the challenge: