Dynamically filtering an array

Tell us what’s happening:

i dont understand what is wrong with my code , it is giving an error message of build error

Your code so far


class MyComponent extends React.Component {
constructor(props) {
  super(props);
  this.state = {
    users: [
      {
        username: 'Jeff',
        online: true
      },
      {
        username: 'Alan',
        online: false
      },
      {
        username: 'Mary',
        online: true
      },
      {
        username: 'Jim',
        online: false
      },
      {
        username: 'Sara',
        online: true
      },
      {
        username: 'Laura',
        online: true
      }
    ]
  }
}
render() {
const usersOnline = this.state.users.filter(i => i.online == true);
  const renderOnline = userOnline.map((i) => <li key={i.username + 1}>{i.username}</li>)
  return (
     <div>
       <h1>Current Online Users:</h1>
       <ul>
         {renderOnline}
       </ul>
     </div>
  );
}
};

Your browser information:

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

Challenge: Use Array.filter() to Dynamically Filter an Array

Link to the challenge:

please can anyone help with these?

const usersOnline make sure this is correct everywhere you need it. Hint: check for typos or missed letters in your map :slight_smile:

I am SO bad at doing this, so it’s always the first thing I check now :smiley:

1 Like

Thank you !
i had been looking at it since and even had and hint pointing it out abd i still didnt realise .
Now i feel stupid :joy:

Ah, definitely don’t feel stupid. Most IDE’s will pick this up for you, but it’s a REALLY good habit to be able to type code without that help while you’re learning.

Especially typing all the brackets and stuff too, so you know where they should be.

At least now you’ve learned that if things don’t work right when they should that it could be something like that.