Tell us what’s happening:
An iterator should be used. failuresList should be equal to the specified output. failuresList should be an array containing result failure messages.
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 = [`['<li class="text-warning">${result.failure[0]}</li>',\n<'li class="text-warning">${result.failure[1]}</li>',\n'<li class="text-warning">${result.failure[2]}</li>'\n]`];
// Only change code above this line
console.log(failureItems)
return failureItems;
}
const failuresList = makeList(result.failure);
Your browser information:
User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:83.0) Gecko/20100101 Firefox/83.0.
This is not the way you should do the challenge. In this case only 3 elements are there in the failure array, but there may be hundreds of elements. Therefore, you should always use an iterator(loop).
This is not an array, but the list. You’ve to create an array containing the strings with <li>...</li>.
You’ve used result.failure.length or arr.length in your array. why?
Because, you wanted to use the items from this array using index.
In above snippet, you’ve used nothing but the index of the required text.
You just have to create an empty array, then in the loop, create new string using string literals and the index and then push the string to the array.
In this way, you didn’t know the length of array. The program will always work if any entries from the original array(result are are changed)
Hope I am clear!!
Array containing the text <li .....</li>, for each element in arr
Why you initialized this array
Because you have to add the text mentioned above in this array
Why are you pushing the text to `arr`
You don’t have to add elements in this arr, instead you’ve to add them in the array you’ve initialized as empty, i.e. failureItems.
Why are you using `${}` here
You’ve to add items from the arr here, such as ${arr[0]} for the first one, ${arr[1]} for the second one.
You can’t do above thing for multiple times, if there are more than 10, 100 or maybe 1000 elements in the arr, Hence you need to use the loop.
Please think upon, above questions and their answers.
Hope, it’ll be clear now.
Exactly. You’ll have to declare the empty array, before adding the elements in it…
You’ve declared the array using const failure items=[],but after the loop…
Just declare it before the loop, so that you can use it.