2018-10-12 15:37:13 -04:00
---
title: Create Strings Using Template Literals
---
2019-07-24 00:59:27 -07:00
# Create Strings Using Template Literals
---
## Problem Explanation
2018-10-12 15:37:13 -04:00
Instead of using string concatenation, ES6 offers template literals to create strings. In this challenge, you have to use template literals to create an array of text warnings.
2019-07-24 00:59:27 -07:00
It's required to use template literals to return a list as every element in the array as the element will be wrapped in a `<li></li>` tag.
2018-10-12 15:37:13 -04:00
2019-07-24 00:59:27 -07:00
---
## Hints
2018-10-12 15:37:13 -04:00
2019-07-24 00:59:27 -07:00
### Hint 1
2018-10-12 15:37:13 -04:00
* Use `map()` function to apply the template literals on all of the `arr` elements
2019-07-24 00:59:27 -07:00
### Hint 2
2018-10-12 15:37:13 -04:00
* Inside the `map()` use an arrow function which has `element` as a parameter and returns `<li></li>` that has the text-warning class and containing the `element` inside it
2019-07-24 00:59:27 -07:00
< details > < summary > Solution 1 (Click to Show/Hide)< / summary >
2018-10-12 15:37:13 -04:00
2019-07-24 00:59:27 -07:00
```javascript
const resultDisplayArray = arr.map(item => `<li class="text-warning">${item}</li>` );
```
< / details >
2018-10-12 15:37:13 -04:00
2019-07-24 00:59:27 -07:00
< details > < summary > Solution 2 (Click to Show/Hide)< / summary >
2018-10-12 15:37:13 -04:00
2019-07-24 00:59:27 -07:00
No map() solution
2018-11-07 15:34:13 +00:00
Despite being a less flexible solution, if you know the number of elements in advance, you can enumerate them as in
2018-10-12 15:37:13 -04:00
2019-07-24 00:59:27 -07:00
```javascript
const resultDisplayArray = [`<li class="text-warning">${arr[0]}</li>` ,
2018-10-12 15:37:13 -04:00
`<li class="text-warning">${arr[1]}</li>`
2019-07-24 00:59:27 -07:00
,`<li class="text-warning">${arr[2]}</li>` ];
```
< / details >