1function makeList() {
2 // Establish the array which acts as a data source for the list
3 let listData = [
4 'Blue',
5 'Red',
6 'White',
7 'Green',
8 'Black',
9 'Orange'
10 ],
11 // Make a container element for the list
12 listContainer = document.createElement('div'),
13 // Make the list
14 listElement = document.createElement('ul'),
15 // Set up a loop that goes through the items in listItems one at a time
16 numberOfListItems = listData.length,
17 listItem,
18 i;
19
20 // Add it to the page
21 document.getElementsByTagName('body')[0].appendChild(listContainer);
22 listContainer.appendChild(listElement);
23
24 for (i = 0; i < numberOfListItems; ++i) {
25 // create an item for each one
26 listItem = document.createElement('li');
27
28 // Add the item text
29 listItem.innerHTML = listData[i];
30
31 // Add listItem to the listElement
32 listElement.appendChild(listItem);
33 }
34}
35
36// Usage
37makeList();