The questions are viz;
- Create a
displayUsers
arrow function just above thefetchAndDisplayUsers
function. It should take ausers
parameter - It should use the array
.forEach
function to iterate overusers
and populate the SELECT UI element with OPTION elements. Each OPTION should have its value set to theid
of a given user, while its display text should be set to the user’sname
.
I’ve tried to write the following code but still giving error.
const displayUsers = (users) => {
var parent = document.querySelector('select');
users.forEach((user) => {
var option = document.createElement('option');
option.textContent = user.name;
option.setAttribute("value",user.id);
parent.appendChild(option);
});
}
Your help would be highly appreciated, thank you.