---Create Strings using Template Literals---

Tell us what’s happening:

Your 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";

  // change code below this line
  const resultDisplayArray = `<li class="text-warning">${result.failure}</li>`;
  // change code above this line

  return resultDisplayArray;
}
/**
 * makeList(result.failure) should return:
 * [ <li class="text-warning">no-var</li>,
 *   <li class="text-warning">var-on-top</li>, 
 *   <li class="text-warning">linebreak</li> ]
 **/
const resultDisplayArray = makeList(result.failure);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1 Safari/605.1.15.

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

Hi,
result.failure is an array of strings. You need to make a separate result string for each item in that array as in the example.

So far your string looks like this
<li class="text-warning">no-var,var-on-top,linebreak</li>

Good luck

Thanks a lot, now it’s been solved:)

I’m still stuck.

This is what I did.

  const resultDisplayArray = [`<li class="text-warning">${result.failure[0]}</li>`,
                              `<li class="text-warning">${result.failure[1]}</li>`,
                              `<li class="text-warning">${result.failure[2]}</li>`];

Please help.

You need a loop statement, such as for or map instead of writing the strings three times.

use forEach then push each value to the array … You are good to go then…

Look, you should use the template like ${variable}. So the

  • no-var
  • should be like
  • ${variable}
  • . Here is the answer which can let you pass. You can also use the loop method to do it but I think it is not the key point of this task.

    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”;

    // change code below this line
    const resultDisplayArray = [

  • ${arr[0]}
  • ,
  • ${arr[1]}
  • ,
  • ${arr[2]}
  • ]; // change code above this line

    return resultDisplayArray;
    }
    /**

    makeList(result.failure) should return:
    [

  • no-var
  • ,
  • var-on-top
  • ,
  • linebreak
  • ] **/ const resultDisplayArray = makeList(result.failure);

    you ${result.failure[0]} should be changed to ${arr[0]} since the parameter of the test case is result.failure already.

    1 Like