Issues in dot and square bracket notation

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

Link to the challenge:

Why are you users and not obj?
You are asked to : which accepts one argument (a users object).

1 Like

Hey, not all people will know as much as you. Try responding to the question with help so they can learn how to continue on. @KittyKora

1 Like

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.

1 Like

My bad. Thank you for clarifying.

2 Likes

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.

1 Like

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 .

1 Like