From 8c2458103ed5100bf185b76bcf1e893c47d3a4e8 Mon Sep 17 00:00:00 2001 From: Alexis08041992 Date: Mon, 1 Jun 2026 20:35:16 -0300 Subject: [PATCH 1/2] Ejercicio 1 --- estilo.css | 6 ++++++ script.js | 14 ++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/estilo.css b/estilo.css index 040e932..73e911e 100644 --- a/estilo.css +++ b/estilo.css @@ -53,6 +53,12 @@ th, td { border-bottom: 1px solid #e0e0e0; } +/* Centrar columnas específicas (Año y Puntaje) */ +th:nth-child(3), td:nth-child(3), +th:nth-child(4), td:nth-child(4) { + text-align: center; +} + th { background-color: #4a69bd; color: white; diff --git a/script.js b/script.js index 234668b..8532657 100644 --- a/script.js +++ b/script.js @@ -7,8 +7,18 @@ let libros = [ function mostrarTabla(datos) { // Escribir esta función para resolver el punto 1. + const libreria = document.querySelector("#listado_libros"); + + for (const libro of libros){ + const fila = document.createElement("tr"); + fila.innerHTML = ` + ${libro.titulo} + ${libro.autor} + ${libro.anio} + ${libro.puntaje} + `; + libreria.appendChild(fila); + } } - - // Invocamos la función al inicio para poblar la tabla con los datos del array mostrarTabla(libros); -- 2.49.1 From a53c8c4e6fcd0495df43637c602d35248ee89ef9 Mon Sep 17 00:00:00 2001 From: Alexis08041992 Date: Mon, 1 Jun 2026 21:22:54 -0300 Subject: [PATCH 2/2] Ejercicio 2 incompleto --- estilo.css | 6 ------ index.html | 1 + script.js | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 6 deletions(-) diff --git a/estilo.css b/estilo.css index 73e911e..040e932 100644 --- a/estilo.css +++ b/estilo.css @@ -53,12 +53,6 @@ th, td { border-bottom: 1px solid #e0e0e0; } -/* Centrar columnas específicas (Año y Puntaje) */ -th:nth-child(3), td:nth-child(3), -th:nth-child(4), td:nth-child(4) { - text-align: center; -} - th { background-color: #4a69bd; color: white; diff --git a/index.html b/index.html index c975a59..2709e15 100644 --- a/index.html +++ b/index.html @@ -31,6 +31,7 @@

+

diff --git a/script.js b/script.js index 8532657..67f9bfb 100644 --- a/script.js +++ b/script.js @@ -22,3 +22,56 @@ function mostrarTabla(datos) { } // Invocamos la función al inicio para poblar la tabla con los datos del array mostrarTabla(libros); + +const form = document.querySelector("#boton-agregar") + +function taMal(id, mensaje) { + document.querySelector(id).textContent = mensaje; +} + +function yaNoTa(id) { + document.querySelector(id).textContent = "" +} + +form.addEventListener("click", (e) => { + e.preventDefault(); + + const titulo = document.querySelector("#titulo").value.trim(); + const autor = document.querySelector("#autor").value.trim(); + const anio = document.querySelector("#anio").value.trim(); + const calificacion = document.querySelector("#calificacion").value; + + yaNoTa("#error"); + yaNoTa("#error"); + yaNoTa("#error"); + yaNoTa("#error"); + + + let valido = true; + + + if (titulo === "") { + taMal("#error", "El titulo no puede estar vacío."); + valido = false; + } + + if (autor === "") { + taMal("#error", "El autor no puede estar vacío."); + valido = false; + } + + if (anio === "") { + taMal("#error", "El año no puede estar vacío."); + valido = false; + } + + if (calificacion === "" || parseInt(calificacion) < 0 || parseInt(calificacion) > 10) { + taMal("#error", "La calificaion tiene que ser mayor que 0 y menor que 10."); + valido = false; + } + + if (valido) { + document.querySelector("#exito").textContent = "Formulario enviado correctamente."; + form.reset(); // reset() limpia todos los campos del formulario + } +}); \ No newline at end of file -- 2.49.1