Template literal challenge (ES6)

Tell us what’s happening:
Describe your issue in detail here.
is this not working because the value of the constant cannot be changed?

  **Your code so far**

const result = {
success: ["max-length", "no-amd", "prefer-arrow-functions"],
failure: ["no-var", "var-on-top", "linebreak"],
skipped: ["no-extra-semi", "no-dup-keys"]
function makeList(arr) {
// Only change code below this line
for (var i=0; i<arr.length; i++) {
const failureItems = ´['<li class="text-warning">$arr[i]</li>']´;}
// Only change code above this line

return failureItems;

const failuresList = 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/92.0.4515.107 Safari/537.36

Challenge: Create Strings using Template Literals

Link to the challenge:

You keep re-declaring the failureItems on each loop iteration, and it is only scoped to the loop body. You cannot reference failureItems outside of the loop, and even if you could, you need to fix the fact that you keep overwriting the variable on every loop iteration.

1 Like
const failureItems = [];
  for (var i=0; i<arr.length; i++) {
  failureItems.push(`'<li class="text-warning">$arr[i]</li>'`);}

What is the mistake here?

The desired output shown in the instructions has single quotes around the strings to denote that they are strings but you don’t actually include those in the output.

Also, how do you include a variable in a template literal? You are missing some syntax.

1 Like

Why don’t we include the single quotes? Also, if I cannot include var here, then it is let but I am having difficulty understanding the difference it would make here.

Because you are using backticks to define the string in your code instead of single quotes, so the single quotes are unnecessary.

I didn’t say you couldn’t include a variable in the template literal. I said that the syntax you are using is not exactly correct. Look at the example in the instructions to figure out what you are missing.

1 Like

But aren’t the single quotes in this example a part of the string? As far as I could understand, they are not used to specify that it is string but they are supposed be seen in the output.

No, they aren’t, that’s what I was trying to explain. In the example output shown in the instructions, the single quotes signify that strings are stored in the array but you don’t literally add single quotes to the strings in your output.

  '<li class="text-warning">no-var</li>',
  '<li class="text-warning">var-on-top</li>',
  '<li class="text-warning">linebreak</li>'

This means that you have an array of strings. So in your function you want to create an array of strings. You are creating the strings using template literals, which use the backticks instead of single/double quotes. You don’t need to additionally add the single quotes at the beginning/end of the string you create.


I have a similar problem. Have you found a solution?

Yes, as @bbsmooth said the issue was with the syntax. The variable after the $ sign should be in curly brackets { }. That’s also explained in the challenge but I was just not careful enough.

I have a similar problem who can help me?

Can i see an example ?

It’s explained in the instructions, in the example there.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.