This commit is contained in:
Marcos Lopez
2024-01-19 13:49:22 +01:00
parent 96759acedd
commit 085cb5dc63
12 changed files with 549 additions and 0 deletions

View File

@@ -0,0 +1,58 @@
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>02 Bucles javascript</title>
<link rel="stylesheet" href="css/estilos.css" />
</head>
<body>
<h1>Bucles Javascript 02</h1>
<script>
//1 Arrays beneficios y gastos
// Arrays de beneficios y gastos diarios(semana)
const ingresosDiarios = [120, 150, 200, 180, 250, 300, 210];
const gastosDiarios = [50, 60, 40, 80, 90, 70, 60];
// Inicializamos el beneficio neto total
let beneficioNetoTotal = 0;
/*
// Utilizamos un bucle 'for' para calcular el beneficio neto diario y total
for (let dia = 0; dia < ingresosDiarios.length; dia++) {
// Calculamos el beneficio neto diario restando los gastos del beneficio
let beneficioNetoDiario = ingresosDiarios[dia] - gastosDiarios[dia];
// Mostramos el beneficio neto diario
document.write(`Día ${dia + 1}: Beneficio Neto = ${beneficioNetoDiario}`);
document.write("<br>");
// Sumamos el beneficio neto diario al beneficio neto total
beneficioNetoTotal += beneficioNetoDiario;
}
// Mostramos el beneficio neto total al final de la semana
document.write(`Beneficio Neto Total Semanal = ${beneficioNetoTotal}`);
*/
//CON FOR EACH*
// Beneficio neto diario y total
ingresosDiarios.forEach(function(ingreso, dia) {
// Utilizamos la variable 'dia' para acceder a los gastos correspondientes
const gastoDiario = gastosDiarios[dia];
// Calculamos el beneficio neto diario restando los gastos del beneficio
let beneficioNetoDiario = ingreso - gastoDiario;
// Mostramos el beneficio neto diario
document.write(`Día ${dia + 1}: Beneficio Neto = ${beneficioNetoDiario}`);
document.write("<br>");
// Sumamos el beneficio neto diario al beneficio neto total
beneficioNetoTotal += beneficioNetoDiario;
});
document.write("Beneficio Neto Total Semanal ="+beneficioNetoTotal);
</script>
</body>
</html>

View File

@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="../Introduccion/estilos.css">
<script src="./js/main.js"></script>
<title>Document</title>
<script>
</script>
</head>
<body>
<script>
document.write(muestraArray(DIASSEMANA,))
document.write(muestraArray(INGRESOS))
document.write(muestraArray(GASTOS))
document.write(muestraArray(beneficios()))
</script>
</body>
</html>

View File

@@ -0,0 +1,32 @@
const DIASSEMANA = [
"Lunes",
"Martes",
"Miercoles",
"Jueves",
"Viernes",
"Sabado",
"Domingo",
];
const INGRESOS = [120, 150, 200, 180, 250, 300, 210];
const GASTOS = [50, 60, 40, 80, 90, 70, 60];
function muestraArray(array) {
let linea = "";
let relleno = "&nbsp";
array.forEach((el) => {
linea += el;
for (let i = 0; i < 15-(el.toString().length); i++) {
linea +=relleno
}
});
return linea + "<br>";
}
function beneficios() {
let resultado = [];
for (let i = 0; i < DIASSEMANA.length; i++) {
resultado[i] = INGRESOS[i] - GASTOS[i];
}
return resultado;
}