A bug in the Javascript Algorithms and Data Structures section

I’m facing an issue in the section Javascript Algorithms and Data Structures, more specifically the lesson Basic Data Structures: Iterate Through the Keys of an Object with a for…in Statement, here you have the link: https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-data-structures/iterate-through-the-keys-of-an-object-with-a-for---in-statement.

I am running the code which I will attach here, but it doesn’t seem to recognize it as a solution, even though that seems to really be the solution, because the console is showing the right output even when I change the values of true and false in the object.

I may be wrong. That may not be the solution, but as far as I can see, it seems to be a bug.

I’ll be waiting for a response from your side, and if that’s a bug, I’ll be waiting for a fix as well. Please let me know!

Just in case the image doesn’t load up, I’m putting the code here as well:

const users = {
  Alan: {
    online: false
  },
  Jeff: {
    online: true
  },
  Sarah: {
    online: false
  }
}

function countOnline(allUsers) {
  // Only change code below this line
  let count = 0;
  for(let user in allUsers) {
    if(users[user].online === true) {
      count++;
    }
  }
  return count;
  // Only change code above this line
}

console.log(countOnline(users));

Hi there and welcome to the forum!

It’s better if you post code rather than screenshots anyhow.
I’ve edited your post for readability as code doesn’t read well if it’s pasted in directly.
If you use the Preformatted Text tool (</> icon or CTRL+e) it will create two sets of triple backticks between which you can paste your code.

As for your solution, you’ve made one small error:

This line directly references the global object which was created for the challenge (i.e. users). However, you should be working with the parameter which is passed to the function instead (i.e. allUsers).
You should always be working with the function parameters as that allows your function to adapt to whatever argument is passed to it.

If you need help with any future challenges, the easiest method is to click on Get Help then Ask for Help and Create a help post on the forum. This creates a forum post which automatically includes your full code, a link to the challenge and an opportunity to describe the issue you’re facing.

Yeah, I must have taken a little break. That’s an easy fix. Thank you very much.

And yeah, thank you for the advices.

Wish you a great day!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.