ES6: Create Strings using Template Literals – Freecodecamp

I tried solving below problem, passed 3 out of 4 conditions. I’m not able to find anymore errors in my code below. But still it says “failuresList should be an array containing result failure messages.”

Link:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/es6/create-strings-using-template-literals

Problem:
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

[
  '<li class="text-warning">no-var</li>',
  '<li class="text-warning">var-on-top</li>',
  '<li class="text-warning">linebreak</li>'
]
  1. Not passed : failuresList should be an array containing result failure messages.
  2. Passed : failuresList should be equal to the specified output.
  3. Passed : Template strings and expression interpolation should be used.
  4. Passed : An iterator should be used.

Below is my code so far :

const result = {
  success: ["max-length", "no-amd", "prefer-arrow-functions"],
  failure: ["no-var", "var-on-top", "linebreak"],
  skipped: ["id-blacklist", "no-dup-keys"]
};

function makeList(arr) {
  "use strict";
 
 
  // Only change code below this line
  const resultDisplayArray = (arr) =>{
    let failure = [];
   for (let element of arr) {
      failure.push(`<li class="text-warning">${element}</li>`);
    }
  
    return failure;
    
  };
  // Only change code above this line

  return resultDisplayArray(arr);
}

const resultDisplayArray = makeList(result.failure);
console.log(resultDisplayArray);

Leave a Comment