DEV Community

Naveen Dinushka
Naveen Dinushka

Posted on

Strings using template literals (freecodecamp notes)

The ES6 Template literals is a new feauture allowing you to create multi-line strings and to use string interpolation features to create strings.

Use template literal syntax with backticks to create an array of list element (li) strings. Each list element's text should be one of the array elements from the failure property on the result object and have a class attribute with the value text-warning. The makeList function should return the array of list item strings.

Use an iterator method (any kind of loop) to get the desired output (shown below).

[
  '<li class="text-warning">no-var</li>',
  '<li class="text-warning">var-on-top</li>',
  '<li class="text-warning">linebreak</li>'
]
Enter fullscreen mode Exit fullscreen mode

As we are asked to use an iterator we will be using the map function, here's a good article for you to check the usage of map in processing arrays https://www.digitalocean.com/community/tutorials/4-uses-of-javascripts-arraymap-you-should-know

With that the exercise we are given is

const result = {
  success: ["max-length", "no-amd", "prefer-arrow-functions"],
  failure: ["no-var", "var-on-top", "linebreak"],
  skipped: ["no-extra-semi", "no-dup-keys"]
};
function makeList(arr) {

  const failureItems //


  return failureItems;
}

const failuresList = makeList(result.failure);
Enter fullscreen mode Exit fullscreen mode

And the answer with a map function in use

const result = {
  success: ["max-length", "no-amd", "prefer-arrow-functions"],
  failure: ["no-var", "var-on-top", "linebreak"],
  skipped: ["no-extra-semi", "no-dup-keys"]
};
function makeList(arr) {
  // Only change code below this line
  const failureItems = arr.map(e=>`<li class="text-warning">${e}</li>`)

  // Only change code above this line

  return failureItems;
}

const failuresList = makeList(result.failure);

Enter fullscreen mode Exit fullscreen mode

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (1)

Collapse
 
aravind13789216 profile image
Aravind Kumar

what does that "e" do in function makeList

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

AWS GenAI LIVE!

GenAI LIVE! is a dynamic live-streamed show exploring how AWS and our partners are helping organizations unlock real value with generative AI.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️