Given an array of users, write a function, namesAndRoles that returns all of user's names and roles in a string with each value labeled. code example

Example: Given an array of users, write a function, namesAndRoles that returns all of user's names and roles in a string with each value labeled.

const users = [{ name: 'Homer', role: 'Clerk', dob: '12/02/1988', admin: false }, { name: 'Lisa', role: 'Staff', dob: '01/30/1965', admin: false }, { name: 'Marge', role: 'Associate', dob: '09/10/1980', admin: true } ];

function namesAndRoles1(users) {
   return users.map(user => `Name: ${user.name}<br/>Role: ${user.role}${user.admin ? " (admin)":""}<br/>`)
   .join('<hr/>');
}

document.getElementById('output1').innerHTML = namesAndRoles1(users);

function namesAndRoles2(users) {
   return users.map(user => `Name: ${user.name}\nRole: ${user.role}${user.admin ? " (admin)":""}\n`)
   .join('\n');
}


document.getElementById('output2').textContent = namesAndRoles2(users);

Tags:

Sql Example