1

Как использовать строку-шаблон и нижеприведенные данные, чтобы получить вот такой результат:

“There are 4 people on the tooling team. Their names are Jennie, Ronald, Martin, Anneli. 2 of them have a senior role.”

const teamName = "tooling";

    const people = [
    {name: "Jennie", role: "senior"},
    {name: "Ronald", role: "junior"},
    {name: "Martin", role: "senior"},
    {name: "Anneli", role: "junior"}];
    let message = YOUR_CODE_HERE;
    console.log(message);

1 ответ 1

4

Инъекции данных в строку шаблон осуществляются с помощью js-выражений, завёрнутых в сигнатуру ${expression}:

const teamName = "tooling";
const people = [
  {name: "Jennie", role: "senior"},
  {name: "Ronald", role: "junior"},
  {name: "Martin", role: "senior"},
  {name: "Anneli", role: "junior"}
];

let message = `There are ${people.length} people on the ${teamName} team. Their names are ${people.map(p=>p.name).join(', ')}. ${people.filter(p=>p.role==='senior').length} of them have a senior role.”`;

console.log(message);

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.