From f4f6d5544755e19cb2f2a5b4e5e715e1d962bdc6 Mon Sep 17 00:00:00 2001 From: Cris <159848549+CristianCruz0309@users.noreply.github.com> Date: Fri, 30 Jan 2026 20:06:02 -0500 Subject: [PATCH] Refactor note management functionality Refactor script to allow dynamic note addition and limit to 5 notes. Updated functions to handle new array structure. --- proyecto-dia-6/script.js | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/proyecto-dia-6/script.js b/proyecto-dia-6/script.js index 634d4b0..82e7fe1 100644 --- a/proyecto-dia-6/script.js +++ b/proyecto-dia-6/script.js @@ -1,4 +1,26 @@ -let array = [1.7, 3, 2.5, 4.8, 3.6]; +let array = []; + +function agregarNota() { + let input = document.getElementById("inputNota"); + let nota = parseFloat(input.value); + + if (array.length >= 5) { + alert("Solo se permiten máximo 5 notas"); + return; + } + + if (isNaN(nota) || nota < 0 || nota > 5) { + alert("Ingresa una nota válida entre 0 y 5"); + return; + } + + // 🔴 limitar a 1 decimal + nota = Number(nota.toFixed(1)); + + array.push(nota); + input.value = ""; + listarNotas(); +} function listarNotas() { let lista = document.getElementById("listaNotas"); @@ -53,4 +75,5 @@ function hayAplazo() { i++; } while (i < 5); document.getElementById("aplazo").textContent = aplazo; -} \ No newline at end of file + +}