# ES6 - Create Strings using Template Literals

**URL:** <https://forum.freecodecamp.org/t/es6-create-strings-using-template-literals/195157>\
**Category:** Curriculum Help\
**Tags:** javascript\
**Created:** [June 1, 2018, 1:57pm UTC](https://forum.freecodecamp.org/t/es6-create-strings-using-template-literals/195157 "2018-06-01T13:57:45Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![SuchetaDas](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/suchetadas/32/89254_2.png) [@SuchetaDas](https://forum.freecodecamp.org/u/SuchetaDas)\
**Post date:** [June 1, 2018, 1:57pm UTC](https://forum.freecodecamp.org/t/es6-create-strings-using-template-literals/195157/1 "2018-06-01T13:57:45Z")

</div>

I am not understanding why its not passing the test cases.  
I’m using template strings.

```auto
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.map((item) => {
        return `<li class ="text-warning">${item}</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);

```

---

<div class="post-metadata">

**Author:** ![vaidotasp](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/vaidotasp/32/22304_2.png) [@vaidotasp](https://forum.freecodecamp.org/u/vaidotasp)\
**Post date:** [June 1, 2018, 2:13pm UTC](https://forum.freecodecamp.org/t/es6-create-strings-using-template-literals/195157/2 "2018-06-01T14:13:32Z")

</div>

I think there is an extra space in return statement  
`<li class ="text-warning">${item}</li>` Right after `class` you have an extra space. Would that help?

---

<div class="post-metadata">

**Author:** ![SuchetaDas](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/suchetadas/32/89254_2.png) [@SuchetaDas](https://forum.freecodecamp.org/u/SuchetaDas)\
**Post date:** [June 1, 2018, 2:17pm UTC](https://forum.freecodecamp.org/t/es6-create-strings-using-template-literals/195157/3 "2018-06-01T14:17:10Z")

</div>

Thanks . Didn’t notice that. It surely takes every precision.

---

<div class="post-metadata">

**Author:** ![vaidotasp](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/vaidotasp/32/22304_2.png) [@vaidotasp](https://forum.freecodecamp.org/u/vaidotasp)\
**Post date:** [June 1, 2018, 4:12pm UTC](https://forum.freecodecamp.org/t/es6-create-strings-using-template-literals/195157/4 "2018-06-01T16:12:22Z")

</div>

No worries. It is hard to notice every little detail. I was staring at your code and thought that it should work. Then I myself went to the challenge and wrote solution which ended up being exactly the same as yours. And was like WTF it is all the same 😃 Sometimes just re-writing the same thing from the scratch can help.

---

<div class="post-metadata">

**Author:** ![ZeR0ByTe](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/zer0byte/32/90018_2.png) [@ZeR0ByTe](https://forum.freecodecamp.org/u/ZeR0ByTe)\
**Post date:** [June 15, 2018, 9:00pm UTC](https://forum.freecodecamp.org/t/es6-create-strings-using-template-literals/195157/5 "2018-06-15T21:00:57Z")

</div>

Hi people!  
I don’t know if is correct write here or open other post.

Why my code is not valid in this way:

```auto
  // change code below this line
  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>`;
  // change code above this line

```

and is valid this:

```auto
const resultDisplayArray = arr.map(x =>`<li class="text-warning">${x}</li>`);

```

Is not the same result? I have complete the challenge but i want resolve my doubt.

Thanks people!

---

<div class="post-metadata">

**Author:** ![ZeR0ByTe](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/zer0byte/32/90018_2.png) [@ZeR0ByTe](https://forum.freecodecamp.org/u/ZeR0ByTe)\
**Post date:** [June 15, 2018, 9:37pm UTC](https://forum.freecodecamp.org/t/es6-create-strings-using-template-literals/195157/7 "2018-06-15T21:37:00Z")

</div>

Thanks for reply @camperextraordinaire.  
But for the challenge, is not the same? Because the challenge objetive is:

```auto
 * **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> ]
 **/

```

here i left the challenge link:  
[https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/create-strings-using-template-literals/](https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/create-strings-using-template-literals/)

Thanks again!

---

<div class="post-metadata">

**Author:** ![ZeR0ByTe](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/zer0byte/32/90018_2.png) [@ZeR0ByTe](https://forum.freecodecamp.org/u/ZeR0ByTe)\
**Post date:** [June 15, 2018, 9:41pm UTC](https://forum.freecodecamp.org/t/es6-create-strings-using-template-literals/195157/9 "2018-06-15T21:41:02Z")

</div>

I’m an stupid xD. I have not pay attention to the brackets.  
Thanks @camperextraordinaire 🙂

---

<div class="post-metadata">

**Author:** ![AJArt](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ajart/32/92746_2.png) [@AJArt](https://forum.freecodecamp.org/u/AJArt)\
**Post date:** [July 7, 2018, 9:14pm UTC](https://forum.freecodecamp.org/t/es6-create-strings-using-template-literals/195157/10 "2018-07-07T21:14:39Z")

</div>

Hi, I’ve got this in the code:

> const resultDisplayArray = arr.map(item =\> `<li class="text-warning">${item}</li>` );

but I keep getting invalid regular expression flags? I have backticks around the li class and /li but they are not showing properly for some reason here.

Everything displays properly on my Visual Studio program but getting an error in FCC challenge. Any help? Thanks.

I made a screenshot, for some reason looks like the program is not recognizing the template string. Everything recognizes fine in my Visual Studio. Or am I missing something else?

 ![freecodecamptemplateliterals](https://global.discourse-cdn.com/freecodecamp/original/3X/0/0/007c6752ff46293980eca0f09c6798ff85b58d02.PNG)

---

<div class="post-metadata">

**Author:** ![jsharda39](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jsharda39/32/181430_2.png) [@jsharda39](https://forum.freecodecamp.org/u/jsharda39)\
**Post date:** [July 8, 2018, 7:18am UTC](https://forum.freecodecamp.org/t/es6-create-strings-using-template-literals/195157/11 "2018-07-08T07:18:46Z")

</div>

> [@ZeR0ByTe](#):
>
> const resultDisplayArray = arr.map(x =\>`&lt;li class="text-warning"&gt;${x}&lt;/li&gt;`);

do you solve this problem?  
if yes then help us.

---

<div class="post-metadata">

**Author:** ![AJArt](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ajart/32/92746_2.png) [@AJArt](https://forum.freecodecamp.org/u/AJArt)\
**Post date:** [July 8, 2018, 6:22pm UTC](https://forum.freecodecamp.org/t/es6-create-strings-using-template-literals/195157/12 "2018-07-08T18:22:09Z")

</div>

I’m not sure what that code is jsharda39. Still working on this challenge.

---

<div class="post-metadata">

**Author:** ![nidafarooqui](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/nidafarooqui/32/159856_2.png) [@nidafarooqui](https://forum.freecodecamp.org/u/nidafarooqui)\
**Post date:** [July 16, 2018, 6:28am UTC](https://forum.freecodecamp.org/t/es6-create-strings-using-template-literals/195157/13 "2018-07-16T06:28:43Z")

</div>

Same here. I can’t figure out why it says **invalid regular expression flags** even though I used template literals in my code. My solution is very similiar to yours as you can see below.

```auto
const resultDisplayArray = arr.map(element => `<li class="text-warning">${element}</li>`);

```

Any clue to why this doesn’t pass all the test cases? @vaidotasp

---

<div class="post-metadata">

**Author:** ![vaidotasp](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/vaidotasp/32/22304_2.png) [@vaidotasp](https://forum.freecodecamp.org/u/vaidotasp)\
**Post date:** [July 16, 2018, 4:53pm UTC](https://forum.freecodecamp.org/t/es6-create-strings-using-template-literals/195157/14 "2018-07-16T16:53:01Z")

</div>

It seems that you have been doing everything right, but there is a bug with the challenge itself. I would move on from the time being and work on other challenges while this one is fixed.

Here is a thread you can follow work updates on this issue:

> <https://github.com/freeCodeCamp/freeCodeCamp/issues/16358>
>
> Challenge Name
> https://beta.freecodecamp.org/en/challenges/es6/create-strings-using-template-literals
> Issue Description
> The challenge is failing the last test, 'Template strings were used'.
> Browser Information
> Browser Name, Version:
> Operating System: FireFox 57.0 (64-bit) and...

---

<div class="post-metadata">

**Author:** ![MommaTopaz](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/mommatopaz/32/102513_2.png) [@MommaTopaz](https://forum.freecodecamp.org/u/MommaTopaz)\
**Post date:** [January 6, 2019, 7:42am UTC](https://forum.freecodecamp.org/t/es6-create-strings-using-template-literals/195157/15 "2019-01-06T07:42:55Z")

</div>

Just saw this thread…They are asking for work using backticks. It’s pretty simple. The format is layed out below the code. It’s backticks practice. I realize my answer is the bug-answer. Yep.

The answer is:

const resultDisplayArray = [ `<li class="text-warning">no-var</li>`,  
`<li class="text-warning">var-on-top</li>`,  
`<li class="text-warning">linebreak</li>` ]

surround each list item listing line with backticks. I’m such a newb, I don’t know how to right that on here.

---

<div class="post-metadata">

**Author:** ![djoseprogramming](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/djoseprogramming/32/153472_2.png) [@djoseprogramming](https://forum.freecodecamp.org/u/djoseprogramming)\
**Post date:** [June 21, 2020, 4:00am UTC](https://forum.freecodecamp.org/t/es6-create-strings-using-template-literals/195157/16 "2020-06-21T04:00:54Z")

</div>

Hi all, I’m a newb to this. But here’s my understanding with the requirements. Thought I should share this to help you as a newb-point-of-view.

Understanding the requirements:

- `resultDisplayArray` should be an array containing `result failure` messages.  
The result should be an “array” with the elements from result.failure.  
(This should be not limited to .failure, should work also to other elements of result object)

- `resultDisplayArray` should be equal to the specified output.  
Nothing much of it, we’re pretty much aware what is the specified output. The \<li\> output as an element of an “array”.

- Template strings and expression interpolation should be used.  
Apply the template strings - _back tick_ and the _${variable}_  
(This is what the lesson is for so it should not be missing as a requirement.)

- An iterator should be used.  
This was explained in the problem. To use some sort of loop.

Creating the solution:

1. Turn the declaration into an array. Since the array has no element yet, I use [].
2. Check the specified output. I should return the \<li\> as a string element (assumed, due the presence of single quotes) of the array.
3. Just use the “back tick” (instead of “quote” type of string). With that, I could use ${variable} too.
4. Just check the pattern of every elements. Create a loop for this. (Coding for each element one by one is the first solution I could think. But it will not pass the #4 requirement. Loop should make your code neat and simple as one of its functions - but bruh, seriously?!)

---

<div class="post-metadata">

**Author:** ![timocare](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/timocare/32/182198_2.png) [@timocare](https://forum.freecodecamp.org/u/timocare)\
**Post date:** [October 8, 2020, 10:02pm UTC](https://forum.freecodecamp.org/t/es6-create-strings-using-template-literals/195157/17 "2020-10-08T22:02:44Z")

</div>

you are to use backtick (`) not single quote(’). That’s what solves the problem for me. Goodluck

---

<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:19am UTC](https://forum.freecodecamp.org/t/es6-create-strings-using-template-literals/195157/18 "2021-02-02T11:19:03Z")

</div>


