I’m currently on exercise 1 of Test your skills for loops.
Here is my code.
My approach was to use a for loop to loop over the array and each item to the list. I ran into my first problem, which is my console displayed the error:
TypeError: Argument 1 of Node.appendChild is not an object.
I had no idea what this meant. I googled around but couldn’t really find anything. I eventually looked at the marking guide, and I don’t understand the solution there.
for(let i = 0; i < myArray.length; i++) {
let listItem = document.createElement('li');
listItem.textContent = myArray[i];
list.appendChild(listItem);
}
This solution feels random to me, I was hoping to get some clarity on the solution.
what is document.createElement(‘li’);
what is listItem.textContent?
and lastly what is list.appendChild(listItem);
I kind of understand what each of these mean, but this solution would have never occurred to me. Thanks in advance, I hope I was not too confusing. Let me know if you need me to clarify anything