This question has already been answered:

In the cycle, for each pass, 1 new list item should be created - li, so that the total would be 10 list items. However, it gives only 1 point. How to fix?

let out = document.getElementById('out'); let ul = document.createElement('ul'); let li = document.createElement('li'); out.appendChild(ul); for (let i = 0; i < 11; i++) { ul.appendChild(li); ul.children[i] = li; } console.log(ul.children.length); 
 ul { height: 50px; width: 250px; border: 1px solid #000; margin: 10px auto; padding-left: 0; list-style-type: none; } li { background-color: gray; border: 1px solid #000; width: 12px; height: 25px; } 
 <p id="out"></p> 

Reported as a duplicate at Grundy. javascript Nov 20 '18 at 2:33 pm

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

  • string ul.children[i] = li; need not. - Grundy

1 answer 1

 let out = document.getElementById('out'); let ul = document.createElement('ul'); out.appendChild(ul); for (let i = 0; i < 10; i++) { let li = document.createElement('li'); ul.appendChild(li); ul.children[i] = li; } console.log(ul.children.length); 
 ul { height: 50px; width: 250px; border: 1px solid #000; margin: 10px auto; padding-left: 0; list-style-type: none; } li { background-color: gray; border: 1px solid #000; width: 12px; height: 25px; } 
 <p id="out"></p> 

  • How does this code differ from the code in question? What was the problem? How exactly did she decide? - Grundy