Last active
March 7, 2026 00:17
-
-
Save LizardoReyes/f91c50a68ca81a809247e4584de46f5d to your computer and use it in GitHub Desktop.
Día 15: Proyecto Final en TypeScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Día 15: Proyecto Final en TypeScript | |
| interface Tarea { | |
| id: number; | |
| texto: string; | |
| completada: boolean; | |
| } | |
| let tareas: Tarea[] = []; | |
| const input = document.querySelector<HTMLInputElement>("#input"); | |
| const btn = document.querySelector<HTMLButtonElement>("#btn"); | |
| const lista = document.querySelector<HTMLUListElement>("#lista"); | |
| function renderizarTareas(): void { | |
| if (!lista) return; | |
| lista.innerHTML = ""; | |
| tareas.forEach((tarea) => { | |
| const li = document.createElement("li"); | |
| li.textContent = tarea.texto; | |
| if (tarea.completada) { | |
| li.style.textDecoration = "line-through"; | |
| } | |
| li.addEventListener("click", () => { | |
| tarea.completada = !tarea.completada; | |
| renderizarTareas(); | |
| }); | |
| lista.appendChild(li); | |
| }); | |
| } | |
| btn?.addEventListener("click", () => { | |
| if (!input?.value) return; | |
| const nuevaTarea: Tarea = { | |
| id: Date.now(), | |
| texto: input.value, | |
| completada: false, | |
| }; | |
| tareas.push(nuevaTarea); | |
| input.value = ""; | |
| renderizarTareas(); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment