Tell us what’s happening:
This has me completely thrown off. It could be my brain just waking up, but I’m stumped badly on this one. What do the instructions mean when it says to use “for…in” in the coding? It has me completely confused, stumped, and thrown off track.
Your code so far
let users = {
Alan: {
age: 27,
online: false
},
Jeff: {
age: 32,
online: true
},
Sarah: {
age: 48,
online: false
},
Ryan: {
age: 19,
online: true
}
};
function countOnline(obj) {
// change code below this line
// change code above this line
}
console.log(countOnline(users));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36 Avast/72.0.1174.122.
Why you use for-in you can enumerate through objects.
For instance I can call for(a in users) I can then console.log the key (a) or get the value of the key so in this case it would be the age and online properties.
So is that the solution to the loop or is that an example? I’m so confused about all this data structure coding, because I’m working on it to ready myself for my new courses on Monday in school.
I’m sorry. My learning disability is kicking in. It’s been a while today since I’ve been on here to get help, and this loop has me so confused. I’m not sure if I need to put in their names or not, as it confuses me greatly.
Probably take a step back at this point, understand the fundamentals, what a normal for loop is, how the for…in loops enumerates and the for…of iterates. etc
I don’t even remember where I left off at, though. That’s the thing. I move quickly and have had to use the forums and help pages to get help, yet I still never completely understood it because of my learning disability.
Try to make a step back and try to understand the simpler for loop, otherwise you will not be able to use these things confidently
You know yourself, what do you need? A more hand on approach, someone that explain things to you step by step? Written instructions are better or do you prefer someone talking to you?
I can try to suggest the computer programming course on Khan Academy which has coding walkthroughs and has a different approach and may help you better
How do I avoid that challenge? It won’t let me move on to the next part of the lesson unless I complete that challenge. Khan Academy is stubborn for me.