Skip to content

Instantly share code, notes, and snippets.

@LizardoReyes
Last active March 7, 2026 00:17
Show Gist options
  • Select an option

  • Save LizardoReyes/f91c50a68ca81a809247e4584de46f5d to your computer and use it in GitHub Desktop.

Select an option

Save LizardoReyes/f91c50a68ca81a809247e4584de46f5d to your computer and use it in GitHub Desktop.
Día 15: Proyecto Final en TypeScript
// 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