Tell us what’s happening:
I don’t understand why isn’t this program running
Your code so far
let users = {
Alan: {
age: 27,
online: false
},
Jeff: {
age: 32,
online: true
},
Sarah: {
age: 48,
online: false
},
Ryan: {
age: 19,
online: true
}
};
function countOnline(obj) {
// change code below this line
let i = 0;
for (let name in obj) {
if (obj[name].online === true) {
i =+ 1;
}
}
return i;
// change code above this line
}
console.log(countOnline(users));
I also found someone with a very similar solution that worked…
function countOnline(obj) {
// change code below this line
let onlineUsers = 0;
for(let user in obj){
if(obj[user].online === true){
onlineUsers = onlineUsers + 1;
}
}
return onlineUsers;
// change code above this line
}
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Safari/605.1.15
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-data-structures/-iterate-through-the-keys-of-an-object-with-a-for---in-statement