The issue with the solution is that it says the object is called obj, whereas the starting code in the exercise calls it usersObj. The solution is also needlessly complex because of this issue. Hopefully that acts as a good hint as to how the real solution should be written. If not, I’ve broken it down further below:
The solution says this:
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 result = 0;
for (let user in obj) {
if (obj[user].online === true) {
result++;
}
}
return result;
// change code above this line
}
console.log(countOnline(users));
The actual solution only needs to be this:
function countOnline(usersObj) {
// Only change code below this line
let result = 0;
for (let user in usersObj) {
if (usersObj[user].online === true) {
result++;
}
}
return result;
// Only change code above this line
}
As expected of an exercise, the only code that needs to be written is indeed between the //Only change code below/above this line directions.