Assessment for Looping code Skill 1

Hello guys, this is my final code and I am stuck on it. Could anyone take a peek to check what I am doing wrong? Thanks a lot for your time!

let myArray = [‘tomatoes’, ‘chick peas’, ‘onions’, ‘rice’, ‘black beans’];
let list = document.createElement(‘ul’);

function listArray() {
for (let i = 0; i < myArray.length; i++) {
  let element = document.createElement('li');
  li.textContent = myArray[i];
  list.appendChild(element);
}

}
let section = document.querySelector(‘section’);
section.appendChild(list);

listArray();

call the listArray function before append the list

hope that help and have a nice day

@justsomeone, thanks a lot for your time! Have a nice day as well

1 Like

@Luiz_Federico you very welcome and thanks a lot :slight_smile:

1 Like

I switched ‘li’ for ‘element’ in the third line and it worked.

for (i=0; i<myArray.length; i++) {
let element = document.createElement(‘li’);
element.textContent = myArray[i];
list.appendChild(element);

1 Like

need the full code as his issue was append
section.appendChild(list);
before calling
listArray();

1 Like