** Explanation Needed ** Create Strings Using Literal Template

Here’s the link to the challenge:

Here’s one of the solutions:

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) {
  "use strict";
  // change code below this line
  const failureItems = arr.map(item => `<li class="text-warning">${item}</li>`);
  // change code above this line
  return failureItems;
}
const failuresList = makeList(result.failure);

My confusion is how does the function know to push the items from the failure array without using the word failure inside the function?

And how does the word “item” come into play in this code?

const failureItems = arr.map(item => `<li class="text-warning">${item}</li>`);

Thanks in advance!

The function call passes the failure list in.

If you haven’t already learned .map(), I would look it up to get some background information on how this solution works.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.