From 4429e93eaf9409d6269c6edda8ada7a7c020769c Mon Sep 17 00:00:00 2001 From: Juanse Marquez Date: Mon, 1 Jun 2026 18:44:40 -0300 Subject: [PATCH] Solucion ejercicio 2 --- ejercicio2/ejercicio2.js | 21 +++++++++++++++++++++ ejercicio2/index.html | 10 ++++++++++ 2 files changed, 31 insertions(+) diff --git a/ejercicio2/ejercicio2.js b/ejercicio2/ejercicio2.js index 6ce9e92..3174002 100644 --- a/ejercicio2/ejercicio2.js +++ b/ejercicio2/ejercicio2.js @@ -1 +1,22 @@ // Agregar aquí el código javascript +const boton = document.querySelector("#agregar"); + +boton.addEventListener("click", () => { + const campo = document.querySelector("#agregar input"); + const texto = campo.value.trim(); + + const lista = document.querySelector("#lista ul"); + + // Si el campo está vacío, no hacemos nada. + if (texto === "") return; + + // Creamos el nuevo ítem y lo agregamos a la lista. + const item = document.createElement("li"); + item.textContent = texto; + lista.appendChild(item); + + // Limpiamos el campo para que el usuario pueda escribir la próxima tarea. + campo.value = ""; + // Ponemos el cursor nuevamente en el campo: + campo.focus(); +}); diff --git a/ejercicio2/index.html b/ejercicio2/index.html index a6d71cf..310db75 100644 --- a/ejercicio2/index.html +++ b/ejercicio2/index.html @@ -8,6 +8,16 @@

Ejercicio 2

+
+

Lista de tareas

+ +
+
+ + +