I don’t understand how the program knows that user refers to the names of the users? I know that it has been defined as a let variable, but I still don’t get how that means it is automatically referring to the names…
The statement for...in works by assigning a variable to the value of a property of an object. Here’s a simple explanation:
const object = {
a: 1,
b: 2,
c: 3
};
/*What this is essentially doing is, looping through variable
"object" and assigning it's value into "key". So if you put a console.log inside the for...in loop, it will return every property.*/
for (let key in object) {
console.log(key);
}
// This loop will log:
// "a"
// "b"
// "c"
So you’re telling the program that user is referring to the value of the names.
Here’s a web docs of for...in statement that might help you:
I AM also having a difficult time with the same challenge concerning the for…in statements. It’s not clear on how to complete what is presented . Even by me following the “solution” exactly it’s still coming back incomplete. Anyone’s assistance with this quandry would be very much so appreciated.
It’s what is listed as the Solution.I’m sure it’s just a detail that I’m not seeing but I have yet to find where I’m missing it. Your assistance would be very much so appreciated.
is this all your code?
where is the function definition?
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.
AH ! That could be it . When you say the function definintion do you mean
function countOnline(usersObj)?
my apologies I assumed anyone who’d help was familiar with the exercise in question
I don’t understand what you mean @ this point. I’m getting even more confused. I shared with you what was presented and then I was supposed to "Only Change the code below this line " etc.
1st off allow me to thank you for your time it’s very much so appreciated. And if you clicked on the freeCodeCamp Challenge Guide I pasted in my earlier post today that might give you more of what your asking me to provide. I don’t know does that seem unlikely ?
We still need to see everything in your code editor on the right hand side of the challenge screen to be able to help you debug your problem. It can be very hard to help someone when we can’t see absolutely all of the code.
It really helps if you make postings using the ‘Ask for Help’ button
If you have a question about a specific challenge as it relates to your written code for that challenge, just click the Ask for Help button located on the challenge. It will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.
This exercise was hard, not because of the problem, but because it felt like the original code was missing some parts necessary to understand. for instance the actual object we are working on is absent, so it’s hard to figure out that we have to use the object called users. Also, the function calls userObj, which was confusing to me.
I would suggest having the actual object written on top of the code let users = { Alan: { age: 27, online: false }, Jeff: { age: 32, online: true }, Sarah: { age: 48, online: false }, Ryan: { age: 19, online: true } }; and at the bottom having countOnline(users);