ejercicio 6: tabla dinamica de empleados

This commit is contained in:
2026-05-28 13:46:22 -03:00
parent 6b28028009
commit f9f562bf1c
3 changed files with 89 additions and 2 deletions

View File

@@ -1 +1,50 @@
// Agregar aquí el código javascript
const empleados = [
{ nombre: 'Ana', sector: 'Desarrollo', sueldo: 150000 },
{ nombre: 'Luis', sector: 'Diseño', sueldo: 120000 },
{ nombre: 'Marta', sector: 'Desarrollo', sueldo: 160000 },
{ nombre: 'Carlos', sector: 'RRHH', sueldo: 110000 },
{ nombre: 'Julia', sector: 'Diseño', sueldo: 130000 }
];
const tablaEmpleados = document.getElementById('tabla-empleados');
const cuerpoTabla = tablaEmpleados.querySelector('tbody');
const pieTabla = tablaEmpleados.querySelector('tfoot');
function formatearSueldo(valor) {
return `$${valor.toLocaleString('es-AR')}`;
}
function renderizarTabla() {
cuerpoTabla.innerHTML = '';
let totalSueldo = 0;
empleados.forEach((empleado) => {
const fila = document.createElement('tr');
const celdaNombre = document.createElement('td');
celdaNombre.textContent = empleado.nombre;
const celdaSector = document.createElement('td');
celdaSector.textContent = empleado.sector;
const celdaSueldo = document.createElement('td');
celdaSueldo.textContent = formatearSueldo(empleado.sueldo);
fila.appendChild(celdaNombre);
fila.appendChild(celdaSector);
fila.appendChild(celdaSueldo);
cuerpoTabla.appendChild(fila);
totalSueldo += empleado.sueldo;
});
const promedio = Math.round(totalSueldo / empleados.length);
pieTabla.innerHTML = `
<tr>
<td colspan="2"><strong>Sueldo promedio</strong></td>
<td><strong>${formatearSueldo(promedio)}</strong></td>
</tr>
`;
}
renderizarTabla();

View File

@@ -1,2 +1,28 @@
/* Agregar el código CSS necesario para el ejercicio */
body {
font-family: Arial, sans-serif;
margin: 20px;
}
table {
border-collapse: collapse;
width: 100%;
max-width: 600px;
}
th,
td {
border: 1px solid #ccc;
padding: 8px 12px;
text-align: left;
}
th {
background-color: #f4f4f4;
}
tfoot td {
background-color: #fafafa;
}

View File

@@ -2,13 +2,25 @@
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ejercicio 6</title>
<link rel="stylesheet" href="estilo.css">
</head>
<body>
<h1>Ejercicio 6</h1>
<table id="tabla-empleados">
<thead>
<tr>
<th>Nombre</th>
<th>Sector</th>
<th>Sueldo</th>
</tr>
</thead>
<tbody></tbody>
<tfoot></tfoot>
</table>
<script src="ejercicio6.js"></script>
</body>
</html>