Tell us what’s happening:
hey guys, take a look at my code bellow. i’m trying to get a number of users online but I got stuck. can anyone take a look and help me figure out what’s goin on with my code please!
Your code so far
function countOnline(usersObj) {
// Only change code below this line
let users = {
Alan: {
online: false
},
Jeff: {
online: true
},
Sarah: {
online: false
}
};
let result = 0;
for (let user in users) {
if (users[user].online === true) {
result++;
}
}
return result;
// Only change code above this line
}
console.log(countOnline('usersObj'));
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0.
Challenge: Iterate Through the Keys of an Object with a for…in Statement
I think you misunderstood, and I would recomend you to read more carefull.
1 I was asking a question about, why this and not that. Not give flat out the answer. To help them figure it out on their own.
2: The second part was litterly me quoting the texts that’s in the lesson. It was a hint not a task.
Your function takes the argument usersObj, but you do not use it. You have a hardcoded object called users, so your function will always return the same results, no matter what object someone passes to it.
The alternate syntax for accessing object properties is known as bracket notation . In bracket notation , the object name is followed by a set of square brackets . Inside the square brackets , the property name is specified as a string. The previous example of dot notation has been rewritten below to use bracket notation .