Tell us what’s happening:
the challenge is asking for this:
The function countOnline
returns the number of users with the online
property set to true
with my code, it returned 2 as it was the number of users with the “online” property set to “true”. my code works but it’s not accepted.
Please forgive me if I don’t look at the other posts, I want to solve it by myself if I can (I hope that makes sense despite me being here)
What exactly is this challenge asking for? There’s 2 people online, through for in loop (which is what the challenge wants) I got 2, but still it’s not working.
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
}
};
let aa = 0;
function countOnline(obj) {
// change code below this line
for (let x in obj) {
for (let y in obj[x]) {
if (obj[x][y] === true) {
aa++
}
}
}
return aa;
// change code above this line
}
console.log(countOnline(users));
//var person = {fname:"John", lname:"Doe", age:25};
//var text = "";
//var x;
//for (x in person) {
// text += person[x] + " ";
//}
//console.log(obj[x][y]);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36
.
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/