What's Wrong With My for in Statement?


I solved the problem; it was a missing bracket :frowning:

Tell us what’s happening:

Hey all, I’ve been trying to complete this challenge. The code provided in the “Get a Hint” section doesn’t work. I failed the requirement: " The function countOnline should use a for in statement to iterate through the object keys of the object passed to it."

Thanks in advance.

Your code so far

function countOnline(usersObj) {
// Only change code below this line
let result = 0;
for (let user in usersObj)
  if (usersObj[user].online === true) {
  return result;
// Only change code above this line

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.135 Safari/537.36.

Challenge: Iterate Through the Keys of an Object with a for…in Statement

Link to the challenge:

Looking in the code, this is the regex it is matching:


So, it expects your code in the for loop to be wrapped in a curly brace. It’s technically not required here (according to JS rules) but it is considered good practice to use them anyway.

When I wrap the statement of your loop in curly braces, this passes for me.

1 Like

Thanks Kevin, it was that bracket.