function countOnline(Obj) {
// Only change code below this line
function countOnline(obj) {
let result = 0;
for (let user in obj) {
if (obj[user].online === true) {
result++;
}
}
return result;
// change code above this line
}
console.log(countOnline(users));
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36.
Challenge: Iterate Through the Keys of an Object with a for…in Statement
function countOnline(usersObj) {
// Only change code below this line
let result = 0;
for (let user in obj) {
if (obj[user].online === true) {
result++;
}
}
return result;
// Only change code above this line
}
function countOnline(usersObj) {
// Only change code below this line
let result = 0;
for (let users in obj) {
if (obj[users].online === true) {
result++;
}
}
return result;
// Only change code above this line
}
Correct. You are not using the userObj variable from the function signature in your code for the function body. You are instead using the undefined obj variable.
function countOnline(usersObj) {
// Only change code below this line
let result = 0;
for (let users in obj) { // RIGHT HERE, THE VARIABLE obj IS NOT DEFINED
if (obj[users].online === true) { // RIGHT HERE, THE VARIABLE obj IS NOT DEFINED
result++;
}
}
return result;
// Only change code above this line
}
The variable obj is never defined. Only the variable usersObj is defined. You need to use the variable usersObj.
there is no OBJ! there is only usersObj and you should use the usersObj object instead of just obj because it is undefined and there is only usersobj. Makes sense?