But I digress. So I also managed to finish two of the projects for the certification, the Palindrome Checker and the Telephone Number Validator (Regex). I think they are the two easier projects (and I actually enjoyed regex?) so I expect to spend a bit more time working through the other ones. I already looked ahead and they seem pretty difficult!
Anyways, I just want to plop the bit below as a reminder to myself on how to access through the keys of an object, in the below example is by using the For In loop (which I need more practice with).
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
let count = 0;
for (let user in obj) {
console.log(obj[user]["online"])
if (obj[user].online === true){
count++;
}
}
return count;
// change code above this line
}
console.log(countOnline(users));
I got really tripped up with this one. Just a note to myself that I need to use brackets when accessing the key values with a variable!
obj[user]["online"]
or obj[user].online
It was something I was banging my head over for about 30 mins. /bleh
Oh yeah, I changed the blog subdomain from anncc.blogspot.com to anncodes.blogspot.com. Not sure why I didn't think of that to begin with..
No comments:
Post a Comment