feat: add buildList function to create a list from an array of items

This commit is contained in:
2026-05-14 14:47:54 -03:00
parent eda48c462d
commit 1628053703

View File

@@ -76,3 +76,25 @@ const changeImage = () => {
const image = document.querySelector('img');
image.src = "foto2.jpg";
image.alt = 'Locro';}
// Ejercicio 8
const buildList = (arr) => {
const div = document.createElement('div');
div.classList.add('grupo-comidas');
const h2 = document.createElement('h2');
h2.textContent = arr[0];
div.appendChild(h2);
const ul = document.createElement('ul');
for (let i = 1; i < arr.length; i++) {
const li = document.createElement('li');
li.textContent = arr[i];
ul.appendChild(li);
}
div.appendChild(ul);
return div;
};