Thanks, this video’s solution has little flaw, he used the users directly instead of using the arguments “Obj”, I have pass it, but still confuse about the 3 more item from the console.log output, very strange.
It is coming from the test (it has been rewritten on master so it was a bit harder to find the current old test)
- text: The <code>users</code> object contains users <code>Jeff</code> and <code>Ryan</code> with <code>online</code> set to <code>true</code> and users <code>Alan</code> and <code>Sarah</code> with <code>online</code> set to <code>false</code>
testString: assert(users.Alan.online === false && users.Jeff.online === true && users.Sarah.online === false && users.Ryan.online === true, 'The <code>users</code> object contains users <code>Jeff</code> and <code>Ryan</code> with <code>online</code> set to <code>true</code> and users <code>Alan</code> and <code>Sarah</code> with <code>online</code> set to <code>false</code>');
- text: The function <code>countOnline</code> returns the number of users with the <code>online</code> property set to <code>true</code>
testString: 'assert((function() { users.Harry = {online: true}; users.Sam = {online: true}; users.Carl = {online: true}; return countOnline(users) })() === 5, ''The function <code>countOnline</code> returns the number of users with the <code>online</code> property set to <code>true</code>'');'
This challenge is to teach you how you can work with object.
if you look carefully you can see that
let users={{object1},
{object2},{object3}.
}
this is objects warped inside another object. As you know that length of the object is undefined, you can not use for loop here. so you have to use for in loop or for of loop
if it was an array
it should be warped into a squire bracket
users=[{object1},
{object2},{object3}.
}]
now this is an array which is the collection of three object. and the length of the array is 3. so it is irritable . so you can use normal for loop
there is a different function called by the tests that uses a different object to test
you are not passing tests because of return console.log(...), you can’t return a console.log. well, you can, but you are just returning undefined. You need two different lines, one for logging to the console, the other for returning the value