This commit is contained in:
raul 2024-01-29 17:44:55 +01:00
parent 1d3787dc42
commit 5d88c63032
2 changed files with 109 additions and 0 deletions

38
vectores/13.html Normal file
View File

@ -0,0 +1,38 @@
<html>
<head>
<meta name="" charset="UTF-8" content="">
<style>
* {
text-align: center;
}
</style>
</head>
<body>
<script src="./13.js"></script>
<h1>Vector de notas</h1>
<div id="listanotas"></div>
<form id="frm">
<select id="opciones">
<option value=0>Raul</option>
<option value=1>Antonio</option>
</select>
<input type="text" id="noter" name="" value="">
<button type="button" onclick="nota()">Añadir nota</button>
<button type="button" onclick="main()">Mostrar</button>
</form>
<div id="notificar"></div>
<div id="notadiv"></div>
<div id="notamedia"></div>
<div id="tabla"></div>
</body>
</html>

71
vectores/13.js Normal file
View File

@ -0,0 +1,71 @@
var alumnos = ["Raul", "Antonio"]
var notasEntera = [];
var notaFinal = 0;
//var vecTest = [[1, 2][3, 4][5, 6]]
function nota() {
//var alumnoID = document.getElementById('opciones').value;
var alumnoID = parseInt(document.getElementById('opciones').value);
var alumnoNombre = alumnos[alumnoID]
// switch (alumnoSeleccionado) {
// case "alum1":
// alumnoEscrito = "Alumno 1"
// case "alum2":
// alumnoEscrito = "Alumno 2"
// }
var nota = document.getElementById('noter').value;
if (notasEntera.length == 0) {
document.getElementById('listanotas').innerHTML = `${alumnoNombre}: `;
}
// else if () {
//
// }
if (nota >= 0 && nota <= 10 && nota.length != 0) {
} else {
document.getElementById('notificar').innerHTML = `Por favor, inserte una nota válida`;
setTimeout(() => document.getElementById('notificar').innerHTML = ``, 2500);
return;
}
notasEntera.push(parseFloat(nota));
document.getElementById('notificar').innerHTML = `Has añadido la nota ${nota}`;
setTimeout(() => document.getElementById('notificar').innerHTML = ``, 1500);
document.getElementById('listanotas').innerHTML += `${nota} `;
document.getElementById("frm").reset();
}
// TODO: clean this up
//////////////////////////////////////////////////////////////////////////////////////////////////
function main() {
for (let i = 0; i < notasEntera.length; i++) {
notaFinal = notaFinal + notasEntera[i];
}
var notaMinima = Math.min(...notasEntera)
var notaMaxima = Math.max(...notasEntera)
document.getElementById('notadiv').innerHTML = `Las notas combinadas suman ${notaFinal}<br>La nota máxima es ${notaMaxima}<br>La nota mínima es ${notaMinima}`;
setTimeout(() => document.getElementById('notadiv').innerHTML = ``, 5000);
var notaMedia = notaFinal / notasEntera.length;
document.getElementById('notamedia').innerHTML = `La nota media es ${notaMedia.toFixed(2)}`
// document.getElementById('tabla').innerHTML = '<table>'
// for (let i = 0; i < alumnos.length; i++) {
// document.getElementById('tabla').innerHTML += `<tr><td>${alumnos[i]}</td><td>${notasEntera}</td></tr>`
// }
// document.getElementById('tabla').innerHTML += '</table>'
notaFinal = 0;
}