# Create Strings using Template Literals with For Loop

**URL:** <https://forum.freecodecamp.org/t/create-strings-using-template-literals-with-for-loop/220850>\
**Category:** Curriculum Help\
**Tags:** javascript\
**Created:** [August 24, 2018, 5:46pm UTC](https://forum.freecodecamp.org/t/create-strings-using-template-literals-with-for-loop/220850 "2018-08-24T17:46:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![AnnaKarpinska](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/annakarpinska/32/36596_2.png) [@AnnaKarpinska](https://forum.freecodecamp.org/u/AnnaKarpinska)\
**Post date:** [August 24, 2018, 5:46pm UTC](https://forum.freecodecamp.org/t/create-strings-using-template-literals-with-for-loop/220850/1 "2018-08-24T17:46:08Z")

</div>

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

```js

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

> **[freeCodeCamp.org](https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/es6/create-strings-using-template-literals)**
>
> Learn to Code — For Free

---

<div class="post-metadata">

**Author:** ![EdMagal](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/edmagal/32/29891_2.png) [@EdMagal](https://forum.freecodecamp.org/u/EdMagal)\
**Post date:** [August 24, 2018, 5:56pm UTC](https://forum.freecodecamp.org/t/create-strings-using-template-literals-with-for-loop/220850/2 "2018-08-24T17:56:19Z")

</div>

`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. 😃

example:

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

```

---

<div class="post-metadata">

**Author:** ![shimphillip](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/shimphillip/32/158663_2.png) [@shimphillip](https://forum.freecodecamp.org/u/shimphillip)\
**Post date:** [August 24, 2018, 5:57pm UTC](https://forum.freecodecamp.org/t/create-strings-using-template-literals-with-for-loop/220850/3 "2018-08-24T17:57:01Z")

</div>

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

I would skip this one.

---

<div class="post-metadata">

**Author:** ![AnnaKarpinska](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/annakarpinska/32/36596_2.png) [@AnnaKarpinska](https://forum.freecodecamp.org/u/AnnaKarpinska)\
**Post date:** [August 24, 2018, 6:29pm UTC](https://forum.freecodecamp.org/t/create-strings-using-template-literals-with-for-loop/220850/4 "2018-08-24T18:29:48Z")

</div>

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.

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

```

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [February 2, 2021, 11:33am UTC](https://forum.freecodecamp.org/t/create-strings-using-template-literals-with-for-loop/220850/5 "2021-02-02T11:33:04Z")

</div>


