Create Strings using Template Literals - using for loop

Tell us what’s happening:
I am not sure why this wouldn’t work. I loop through the failure list then print them formatted.

The test comments were confusing. So I am not sure what went wrong

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
  const resultDisplayArray = () => {
    var result = [];
    for(var i=0; i<arr.length;i++){
      result.push(`<li class="text-warning">$(arr[i])</li>`)
    }
    return result;
  };
  // 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/72.0.3626.96 Safari/537.36.

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

and

it may be problem.
please try to another variable name.

I don’t know why you are using arrow function in makeList function, but I think below is more simpler.

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
  var resultDisplayArray = [];
  for(var i=0; i<arr.length;i++){
    resultDisplayArray.push(`<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);

Look carefully at the syntax in the example: what you’ve written is not the syntax for template literals.

Also, I’m with @fanfan1609 here: I’m not sure why you’ve made resultDisplayArray a function then put result as an array inside it: why have you not made resultDisplayArray an array? Making it a function means even if you fix the syntax, your code won’t work, due to this line:

return resultDisplayArray;

resultDisplayArray is a function, so you’re just returning that, it doesn’t do anything until you execute it.

return resultDisplayArray(); // <= NOTE the parentheses

would work, but it’s pontless putting it into a function anyway

1 Like