In the JavaScript Data Structures curriculum, I am on the following lesson:
Basic Data Structures: Iterate Through the Keys of an Object with a for…in Statement
My solution matches the one in the guide, and yet it is not being accepted. The code is as follows:
function countOnline(usersObj) {
// Only change code below this line
let result = 0;
for (let user in userObj) {
if (userObj[user].online === true) {
result++;
}
}
return result;
// Only change code above this line
}
The output console displays the following:
// running tests
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
// tests completed
Does anyone know what the problem is? Thank you in advance.
Solution guide link: freeCodeCamp Challenge Guide: Iterate Through the Keys of an Object with a for...in Statement
*Edited to add links.