Tell us what’s happening:
Can someone explain the lesson to me? I’m quite confused as to what they are asking me to do and, how to even begin
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";
// Only change code below this line
const resultDisplayArray = null;
const resultDisplayArray = ${result.succes}
${result.failure} ${result.skipped} ;
//for (i = 0; i < result.length; i++) {
// resultDisplayArray + "<li>";
//}
// Only change code above this line
return resultDisplayArray;
}
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/84.0.4147.89 Safari/537.36.
Challenge: Create Strings using Template Literals
Link to the challenge:
ILM
July 23, 2020, 8:00am
2
you have an array of strings ["no-var", "var-on-top", "linebreak"]
you are asked to iterate over that array and make an array of html strings, like this:
[
'<li class="text-warning">no-var</li>',
'<li class="text-warning">var-on-top</li>',
'<li class="text-warning">linebreak</li>'
]
using template literals for the values from the original array
you could use any method that can iterate over an array, like a loop, like map or forEach…
Okay so I tried with
arr.forEach
// Only change code below this line
const resultDisplayArray = null;
resultDisplayArray.forEach(arr => `<li class="text-warning">${item}</li>`);
// Only change code above this line
and it gives me an error
TypeError: Cannot read property ‘forEach’ of null
miku86
July 23, 2020, 12:05pm
4
Hi,
do you understand what Cannot read property ‘forEach’ of null means?
Yes and the cause of it is the null value they assigned to resultDisplayArray
because it has the value of the null assign it gives an error
but i am suppose not to change it so i have to work my way around it
without altering it
understanding where it comes from adds nothing in this case
hey there @KittyKora , so in that resultDisplayArray is where you are going to place an iterator in place of null,
The comments say you should change the part where null is assigned to the result. And you are passed and array to work with (called “arr”). So do what the challenge is asking you to with the contents of that array and assign the result (a new array of strings) to your result array.
ILM
July 23, 2020, 3:35pm
8
remember also that forEach returns undefined, so you need an other method, or to add some other stuff to your code
also your callback has arr as parameter but then you use item - where did item come from?
miku86
July 24, 2020, 6:29am
9
Understanding this part leads to the conclusion,
that it doesn’t make that much sense to use an array method on a null value.
So either the exercise description is wrong or your understanding of the description is wrong.
Here you have it: