Create Strings using Template Literals with For Loop

Tell us what’s happening:
I used for loop in ‘Create Strings using Template Literals’ but ‘resultDisplayArray is the desired output’ condition is not fulfilled. Can you point me out if there is something wrong with the code?

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
  let resultDisplayArray = [];
  for (let i = 0; i < arr.length; i++) {
    resultDisplayArray[i] += `<li class="text-warning">${arr[i]}</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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36.

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

resultDisplayArray is an array with no elements. Try using .push to add new elements instead of using the addition sign. Addition will convert each element to a string, starting with “undefined” followed by the string you entered. :smiley:

example:

var arr = [];
for (let i = 0; i<3; i++)  arr[i]+="hi";
console.log(arr);  //logs ["undefinedhi", "undefinedhi", "undefinedhi"]

Your code looks correct to me but this challenge contains a known bug.

I would skip this one.

EdMagal - Simple error on my side. I was probably so focused on the fact that I’m working with strings that used concatenation instead of push method. Thank you!
Working code below.

  let resultDisplayArray = [];
  for (let i = 0; i < arr.length; i++) {
    resultDisplayArray.push(`<li class="text-warning">${arr[i]}</li>`);
  }