ES6 - Create Strings using Template Literals - failuresList should be an array containing result failure messages

Tell us what’s happening: Hi all! I keep on getting the error “failuresList should be an array containing result failure messages”. I’ve been debugging, googling and checking the forums for hours now with no success. I expect to be at least close to what’s required and not completely lost. Any hint is appreciated. Thanks!
Describe your issue in detail here.

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

Challenge: ES6 - Create Strings using Template Literals

Link to the challenge:

The arr variable is what is being passed into the makeList function. You are basically wiping that out by setting it to 0 here.

Again, arr is the array being passed into the function. Do you really want to push to that array, or do you want to push to the array you are returning?

Also, push is a method (or function), so you have to call it with parentheses, not square brackets.

There are other issues, but you need to fix some of these basic errors before you can move on to those.

Hi! thank you. As per your indications I replaced “for (arr = 0;” for for (let i = 0; (also included let, which was missing), and arr.push[…] for failureItems.push() to push to the returning array. Still, I kept on getting the same error. After multiple attempts and combinations I got it working, but I would appreciate if somebody could explain to me these couple lines of code, since it’s a bit confusing for me, mostly what’s included on the literal (${arr[i]} instead of ${result.failure[arr]}):

for (let i = 0; i < result.failure.length; i++) {

  • failureItems.push(<li class="text-warning">${arr[i]}</li>);*

}

Thanks!

Hi again! got it also working with the code below, which is easier to understand for me:

function makeList(arr) {
const failureItems = ;
for (let i = 0; i < result.failure.length; i++) {
failureItems.push(<li class="text-warning">${result.failure[i]}</li>);

}

thank you for your help!

Yes, your solution does work, but you are not using the arr passed into the function to solve the problem. What if instead of calling the function as:

makeList(result.failure)

We called it as

makeList(result.skipped)

Your solution would still pull from results.failure instead of from results.skipped.

I would fix your solution so that it uses the arr passed into the function instead of hard coding from the result object.

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