Refactor note management functionality

Refactor script to allow dynamic note addition and limit to 5 notes. Updated functions to handle new array structure.
This commit is contained in:
Cris
2026-01-30 20:06:02 -05:00
committed by GitHub
parent 6995f3128d
commit f4f6d55447
+25 -2
View File
@@ -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() { function listarNotas() {
let lista = document.getElementById("listaNotas"); let lista = document.getElementById("listaNotas");
@@ -53,4 +75,5 @@ function hayAplazo() {
i++; i++;
} while (i < 5); } while (i < 5);
document.getElementById("aplazo").textContent = aplazo; document.getElementById("aplazo").textContent = aplazo;
}
}