Template Literals using for loop (help)

The program is supposed to print this:

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> ]

so far i have this:


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";
 for (var i = 0; i < result.failure.length; i++) {

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

  return resultDisplayArray;

I feel so close to getting this but the loop isn’t printing out the rest of the elements in the result.failure array. Got any clues as to why? I did look up some solutions but most people used the map function.

Thanks in advance.

are you treating resultDisplayArray as an array?
how do you add values to an array?

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.

markdown_Forums

I think I am treating resultDisplayArray as an array. But i think i’m trying to create an array with ${result.failure[i]}

how do you add values to an array?

It looks like there are two issues here:

  • Parameter arr is never referenced. Either remove it and continue referencing result.failure or change your references to result.failure to arr. This isn’t causing you’re issue, but could cause a debugging difficulty down the line.
  • return is ending the for loop and existing the function.

P.S. Also, you should put “use strict” at the top of your file.

Happy Coding! :smiley: