Tell us what’s happening:
I’m getting stuck on this challenge. I’ve read through a few of the topics on this forum but can’t find a straight forward answer to the problem. The solution proposed also doesn’t seem to work. I’m going around in circles. Thanks in advance for your responses. Me and Javascript don’t get on very well.
Your code so far
const users = {
Alan: {
online: false
},
Jeff: {
online: true
},
Sarah: {
online: false
}
}
function countOnline(usersObj) {
// Only change code below this line
let countOnline = 0;
for (let users in usersObj){
if (users.online === true) {countOnline +=1;}
};
return countOnline;
// Only change code above this line
}
console.log(countOnline(users));
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36
Challenge: Basic Data Structures - Iterate Through the Keys of an Object with a for…in Statement
Link to the challenge: