Need help with loop Task 1

Hi, I’m stuck with the loop test 1. The result only lists the last item in the array, I think possibly it is not creating a new list item each time but writing over the first item hence leaving last item showing only. Not sure where I’m going wrong.

the code;

the test;

would appreciate any help,


Hi @nickmaskell

Exactly. Because the line creating the <li> is outside the loop it only gets create once. Then, its content gets replaced every round of the loop.

You need to move one line in your code to make it work correctly. Can you find out which one?


ahh, thanks, got it. I thought item variable would reference the createElement.

1 Like

The thing is: appendChild() will append new elements, but will move existing elements. Since the <li> was created outside, it was just “moved” to the same position every round.