function countOnline(usersObj) {
// Only change code below this line
for (let user in usersObj) {
console.log(user);
for (let online in user) {
console.log(online);
}
}
// Only change code above this line
}
If you have an object of objects, then your current code will print the key for each object in usersObj and followed by the keys in that object. Is that what you are trying to do?
Sorry. I misread before. You’re doing for(let online in user) you’ll just be printing the index of every letter in the key. I thought you had for(let online in useraObj[user]).
Here is my code now, but still nothing is printed in the console:
function countOnline(usersObj) {
// Only change code below this line
for (let user in usersObj[user]) {
console.log(user);
for (let online in usersObj[user]) {
console.log(online);
}
}
// Only change code above this line
}
How can you loop over user in usersObj[user] ? What do you think this should be doing?
I really am not sure what is going on in this code. The link you provided to the challenge is broken, so I’m not sure what the challenge is. Is this the challenge where you loop over an array of users and count how many are online?
function countOnline(usersObj) {
// Only change code below this line
for (let user in usersObj) {
console.log(user);
for (let online in usersObj[user]) {
console.log(online);
}
}
// Only change code above this line
}
If you aren’t calling the function (which you aren’t in the code you’ve shown) then nothing will happen. Do you have an example where you called the code?
It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.
We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.
You aren’t accessing the online property of a specific usersObj[user] . The for loop syntax is not how you access a property. Why not try dot or bracket notation.