Have problem in Create Strings using Template Literals Challenge

I have a problem with my code. I want to display 3 times
What are my mistakes and how can I solve this challenge!?

My 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 (let i = 0; i <= result['failure'].length; i++) {
return   [`<li class="text-warning">${result.failure[i]}</li>`];

 }
 
 // Only change code above this line

 return arr;
}

const failuresList = makeList(result.failure);
console.log(failuresList);


My output is [ '<li class="text-warning">no-var</li>' ] . But the challenge tell my to return => [ '<li class="text-warning">no-var</li>', '<li class="text-warning">var-on-top</li>', '<li class="text-warning">linebreak</li>' ]

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:81.0) Gecko/20100101 Firefox/81.0.

Challenge: Create Strings using Template Literals

Link to the challenge:

You have a couple of problems going on here.

First of all, they are passing in the array that they want you to use as “arr”. Don’t use the global variable of result.failures.

Secondly, you are returning the string with:

return   [`<li class="text-warning">${result.failure[i]}</li>`];

But if you return, it will leave the function. You will only return that array that you’ve specified there. But you need find a way to get these strings into the array of failureItems. There are a couple of ways to do this. One would be to map those values to a new array. Another would be to find a way to push each of those strings onto the empty array that is defined.

Lastly, you changed the return statement. You changed it to return arr; - it was originally return failureItems;.

I would suggest resetting the code to get it back to a good starting point. See how far you can get with the hints provided.

1 Like