68 lines
1.8 KiB
JavaScript
68 lines
1.8 KiB
JavaScript
// Vincular este archivo al archivo index.html, y resolver aquí los ejercicios.
|
|
|
|
// Ejercicio 1
|
|
const changeText = (str) => {
|
|
const h1 = document.querySelector("h1");
|
|
h1.textContent = str;
|
|
}
|
|
|
|
// Ejercicio 2
|
|
const addClass = (className) => {
|
|
const itemLista = document.querySelectorAll("li");
|
|
itemLista.forEach((item) => {
|
|
item.classList.add(className);
|
|
});
|
|
}
|
|
|
|
// Ejercicio 3
|
|
const agregarItem = (text) => {
|
|
const list = document.querySelector("#lista-inicial");
|
|
const newLi = document.createElement("li");
|
|
newLi.textContent = text;
|
|
list.appendChild(newLi);
|
|
}
|
|
|
|
// Ejercicio 4
|
|
const parrafos = document.querySelectorAll("#parrafos p");
|
|
|
|
parrafos.forEach((p) => {
|
|
if (p.textContent.toLowerCase().includes("importante")){
|
|
p.classList.add("destacado");
|
|
}
|
|
});
|
|
|
|
// Ejercicio 5
|
|
const agregarSec = () => {
|
|
const div = document.createElement("div");
|
|
const body = document.querySelector("body");
|
|
body.appendChild(div);
|
|
|
|
const h2 = document.createElement("h2");
|
|
h2.textContent = "Comidas tipicas del litoral";
|
|
div.appendChild(h2);
|
|
|
|
const parrafo = document.createElement("p");
|
|
parrafo.textContent = "El litoral tiene una gran variedad de Exquisiteses aqui les presentamos algunas de ellas";
|
|
div.appendChild(parrafo);
|
|
|
|
const ul = document.createElement("ul");
|
|
const comidas = ["Chipa","Sopa paraguaya","Pacu","Surubi","Mbeju"];
|
|
comidas.forEach((comida) => {
|
|
const li = document.createElement("li");
|
|
li.textContent = comida;
|
|
ul.appendChild(li);
|
|
});
|
|
|
|
div.appendChild(ul);
|
|
}
|
|
|
|
// Ejercicio 6
|
|
const limpiarList = (id) => {
|
|
const limpiar = document.getElementById(id);
|
|
while(limpiar.firstChild){
|
|
limpiar.removeChild(limpiar.firstChild);
|
|
}
|
|
}
|
|
|
|
|