Create a "displayusers" function that iterates over its parameter and updates its ui

The above “displayUsers” function is giving me error. See the above error message:

  const displayUsers = (users) => {
    console.log("step 3 displayUsers");
    users.forEach(user => {
      const select = document.querySelector('.select-text');
      const option = document.createElement('option');
      option.text = user.name;
      option.value = user.id;
      select.appendChild(option);
  };
  
  const fetchAndDisplayUsers = () => {
    users.push({
      age: 40,
      weight: 75,
      height: 6,
      country: 'Nigeria',
      name: 'Charles Odili',
      id: 'dfhb454768DghtF'
    });

    displayUsers(users);
  };
  
  const startApp = () => {
    console.log("step 1");
    powerupTheUI();
    fetchAndDisplayUsers();
            
  };

  onload= startApp();
  
</script>

Hi @dotun,

I don’t see the actual error message that you see in the post. Could you please add it?

Looking at the code you shared, I see a couple of minor issues,

  1. displayUsers() is missing closing braces. You may want to add this,
});
}
  1. You’ll have to define users as an array before you do users.push()

You can try the above two fixes and check if it works as expected for you.

Hi @divakaran23

The error message still the same

const displayUsers = (users) => {
console.log(“step 3 displayUsers”);
users.forEach(user => {
const select = document.querySelector(’.select-text’);
const option = document.createElement(‘option’);
option.text = user.name;
option.value = user.id;
select.appendChild(option);
});
}

@dotun,
What is the error message that you get? Can you share it?