First you need to have a correct conditional in your if statement. user.online isn’t giving anything. You need to retrieve its value then access .online.
Next, don’t return count too early. Make sure you return it after the loop.
That was a very good attempt at the problem. What I think you are looking for is of, instead of in. I had this problem many times, personally. let user in obj means that user will be an index not object. Thus when you say user.online what you are actually doing is 5.online which of course can’t happen. Here is a refrence for in, change in to of and you get your desired outcome, but you might need to correct your checks but I think you are heading the right direction!
Ah on the note if you plan to use in instead of, remember to use the array notation [] such as obj[user], thus you can do something like obj[user].online === true check. But, using in (user is an number of the current position of the user in the array and not an actual user) means you are getting an index not the object in general but a tip non the less for the problem.
Thank you @Hazecode for all of your help! I’m going to try to use the in instead of of but I noticed I do tend to forget the array notation [] so thank you for that tip! Will definitely have to get better at that. And thank you for the MDN references, I appreciate it! I’ve never used the for of before so I learned something new!
Oh my goodness, that was it!! Yay! I was for sure putting my return too early and it worked once I moved it further down. I also made the noted change in my conditional to include the [] so this part looks like this now: if (obj[user].online == true) { count++; Thanks friend!
Thanks everyone for all the helpful replies in the thread, I managed to get my code to pass the tests.
However, I was still wondering why, when we use bracket notation for the if statement (e.g. [obj][user][‘online’]. that we only put the last part (online) into quotation marks?
I was under the (incorrect) impression that we would need to use quotation marks for any keys/values we were using bracket notation with.
Thanks for the quick response Randall,
I think I understand now, we only use quotation marks when referring explicitly to a property in an object.
Both ‘obj’ and ‘user’ were variables in the function and therefore don’t need the quotation marks.
The reason you would not use [obj] is because obj is the actual object. It is a variable, but it is not a property. It is really the fact the user is a variable and represents a property of an object you want to access.