kindly please assist me pass this challenge , i have done all i could
:
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
for (let users in users){
console.log(online);
}
// change code above this line
}
console.log(countOnline(users));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:66.0) Gecko/20100101 Firefox/66.0
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-data-structures/-iterate-through-the-keys-of-an-object-with-a-for---in-statement/
The challenge is asking you to iterate through the users and count how many are online (i.e. online: true
). Your current solution is simply logging on the console and not counting anything.
can u just give instances on it?
In the current implementation, there are 2 users with the property online: true
. Your solution should return 2
in this scenario.
This part is a good start: for (let user in users)
, but you need to add a conditional statement within the for loop to count the number of users that are online.
i have created a variable : let count = 0, after that inside the function , i now return count+=, if( users ==true). but is not still passing .
I just looked at the challenge this is the solution for the function part:
function countOnline(obj) {
// change code below this line
let count = 0;
for(let user in users){
if(users[user].online)
count++;
}
// change code above this line`
return count;
}
That’s all
thanks for your contribution, but the code refuse to pass
please someone should assist on the challenge please…
function countOnline(obj) { // change code below this line let count = 0; for(let user in users){ if(users[user].online) count++; } // change code above this line return count; }
Oh okay.
I just run it again and it pass.
Please share your solution when it passes
What are you still struggling with? Could you post the updated code that you tried?