arreglos- tres versiones interactivas del ejercicio,
- Obtener vínculo
- X
- Correo electrónico
- Otras apps
Te voy a preparar tres versiones interactivas del ejercicio, cada una con su propio tema para que los alumnos trabajen con arreglos pero de manera entretenida.
1️⃣ Películas favoritas 🎬
html<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<title>Películas favoritas</title>
<style>
body { font-family: Arial, sans-serif; background: #f4f4f4; text-align: center; padding: 20px; }
table { margin: 20px auto; border-collapse: collapse; width: 60%; background: white; }
th, td { border: 1px solid #ddd; padding: 8px; }
th { background: #333; color: white; }
button { padding: 6px 12px; cursor: pointer; border: none; }
.btn-eliminar { background: red; color: white; }
.btn-eliminar:hover { background: darkred; }
.btn-agregar { background: #3498db; color: white; }
.btn-agregar:hover { background: #2980b9; }
</style>
</head>
<body>
<h1>🎬 Mis Películas Favoritas</h1>
<input type="text" id="entrada" placeholder="Escribe una película">
<button class="btn-agregar" onclick="agregarElemento()">Agregar</button>
<table>
<thead><tr><th>#</th><th>Película</th><th>Acción</th></tr></thead>
<tbody id="tablaCuerpo"></tbody>
</table>
<script>
let peliculas = [];
function agregarElemento() {
let valor = document.getElementById("entrada").value.trim();
if (valor) { peliculas.push(valor); document.getElementById("entrada").value = ""; mostrarTabla(); }
}
function mostrarTabla() {
let cuerpo = document.getElementById("tablaCuerpo");
cuerpo.innerHTML = "";
peliculas.forEach((item, index) => {
cuerpo.innerHTML += `<tr><td>${index+1}</td><td>${item}</td>
<td><button class="btn-eliminar" onclick="eliminarElemento(${index})">❌ Eliminar</button></td></tr>`;
});
}
function eliminarElemento(i) { peliculas.splice(i, 1); mostrarTabla(); }
</script>
</body>
</html>
2️⃣ Puntajes de fútbol ⚽
Incluye suma y promedio.
html<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<title>Puntajes de Fútbol</title>
<style>
body { font-family: Arial, sans-serif; background: #f4f4f4; text-align: center; padding: 20px; }
table { margin: 20px auto; border-collapse: collapse; width: 60%; background: white; }
th, td { border: 1px solid #ddd; padding: 8px; }
th { background: #333; color: white; }
button { padding: 6px 12px; cursor: pointer; border: none; }
.btn-eliminar { background: red; color: white; }
.btn-eliminar:hover { background: darkred; }
.btn-agregar { background: #2ecc71; color: white; }
.btn-agregar:hover { background: #27ae60; }
</style>
</head>
<body>
<h1>⚽ Puntajes de Fútbol</h1>
<input type="number" id="entrada" placeholder="Goles del partido">
<button class="btn-agregar" onclick="agregarElemento()">Agregar</button>
<table>
<thead><tr><th>#</th><th>Goles</th><th>Acción</th></tr></thead>
<tbody id="tablaCuerpo"></tbody>
</table>
<h3 id="resumen"></h3>
<script>
let goles = [];
function agregarElemento() {
let valor = document.getElementById("entrada").value;
if (valor !== "") { goles.push(Number(valor)); document.getElementById("entrada").value = ""; mostrarTabla(); }
}
function mostrarTabla() {
let cuerpo = document.getElementById("tablaCuerpo");
cuerpo.innerHTML = "";
goles.forEach((item, index) => {
cuerpo.innerHTML += `<tr><td>${index+1}</td><td>${item}</td>
<td><button class="btn-eliminar" onclick="eliminarElemento(${index})">❌ Eliminar</button></td></tr>`;
});
let total = goles.reduce((a,b) => a+b, 0);
let promedio = goles.length ? (total / goles.length).toFixed(2) : 0;
document.getElementById("resumen").textContent = `Total de goles: ${total} | Promedio por partido: ${promedio}`;
}
function eliminarElemento(i) { goles.splice(i, 1); mostrarTabla(); }
</script>
</body>
</html>
3️⃣ Comidas favoritas 🍕
html<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<title>Comidas favoritas</title>
<style>
body { font-family: Arial, sans-serif; background: #f4f4f4; text-align: center; padding: 20px; }
table { margin: 20px auto; border-collapse: collapse; width: 60%; background: white; }
th, td { border: 1px solid #ddd; padding: 8px; }
th { background: #333; color: white; }
button { padding: 6px 12px; cursor: pointer; border: none; }
.btn-eliminar { background: red; color: white; }
.btn-eliminar:hover { background: darkred; }
.btn-agregar { background: orange; color: white; }
.btn-agregar:hover { background: darkorange; }
</style>
</head>
<body>
<h1>🍕 Mis Comidas Favoritas</h1>
<input type="text" id="entrada" placeholder="Escribe una comida">
<button class="btn-agregar" onclick="agregarElemento()">Agregar</button>
<table>
<thead><tr><th>#</th><th>Comida</th><th>Acción</th></tr></thead>
<tbody id="tablaCuerpo"></tbody>
</table>
<script>
let comidas = [];
function agregarElemento() {
let valor = document.getElementById("entrada").value.trim();
if (valor) { comidas.push(valor); document.getElementById("entrada").value = ""; mostrarTabla(); }
}
function mostrarTabla() {
let cuerpo = document.getElementById("tablaCuerpo");
cuerpo.innerHTML = "";
comidas.forEach((item, index) => {
cuerpo.innerHTML += `<tr><td>${index+1}</td><td>${item}</td>
<td><button class="btn-eliminar" onclick="eliminarElemento(${index})">❌ Eliminar</button></td></tr>`;
});
}
function eliminarElemento(i) { comidas.splice(i, 1); mostrarTabla(); }
</script>
</body>
</html>
Con estos tres archivos (peliculas.html, futbol.html, comidas.html) ya tienes tres ejercicios divertidos y fáciles para trabajar crear, mostrar y eliminar elementos de arreglos.
Si quieres, también puedo unirlos en un solo archivo con un menú para elegir el tema y que los niños cambien de ejercicio sin cambiar de página.
¿Quieres que te lo combine así en versión todo-en-uno?
- Obtener vínculo
- X
- Correo electrónico
- Otras apps
Comentarios
Publicar un comentario