From 6b28028009c6702cfbedcf6d35274502192a3aa2 Mon Sep 17 00:00:00 2001 From: Sergio Madera De Marco <37299705@terciariourquiza.edu.ar> Date: Thu, 28 May 2026 13:40:59 -0300 Subject: [PATCH] ejercicio 5: filtro de lista en tiempo real --- ejercicio5/ejercicio5.js | 44 +++++++++++++++++++++++++++++++++++++++- ejercicio5/estilo.css | 26 ++++++++++++++++++++++++ ejercicio5/index.html | 7 ++++++- 3 files changed, 75 insertions(+), 2 deletions(-) diff --git a/ejercicio5/ejercicio5.js b/ejercicio5/ejercicio5.js index 6ce9e92..13b32d1 100644 --- a/ejercicio5/ejercicio5.js +++ b/ejercicio5/ejercicio5.js @@ -1 +1,43 @@ -// Agregar aquí el código javascript +const paises = [ + 'Argentina', + 'Brasil', + 'Canadá', + 'Dinamarca', + 'España', + 'Filipinas', + 'Grecia', + 'Hungría', + 'India', + 'Japón', + 'México', + 'Noruega' +]; + +const filtroInput = document.getElementById('filtro'); +const listaPaises = document.getElementById('lista-paises'); + +function renderizarLista(items) { + listaPaises.innerHTML = ''; + + items.forEach((pais) => { + const li = document.createElement('li'); + li.textContent = pais; + listaPaises.appendChild(li); + }); +} + +function filtrarPaises(texto) { + const valor = texto.trim().toLowerCase(); + if (valor === '') { + return paises; + } + + return paises.filter((pais) => pais.toLowerCase().includes(valor)); +} + +filtroInput.addEventListener('input', (event) => { + const paisesFiltrados = filtrarPaises(event.target.value); + renderizarLista(paisesFiltrados); +}); + +renderizarLista(paises); diff --git a/ejercicio5/estilo.css b/ejercicio5/estilo.css index 159b7f6..94dbdfb 100644 --- a/ejercicio5/estilo.css +++ b/ejercicio5/estilo.css @@ -1,2 +1,28 @@ /* Agregar el código CSS necesario para el ejercicio */ +body { + font-family: Arial, sans-serif; + margin: 20px; +} + +label, +input { + display: block; + margin-bottom: 10px; +} + +input { + padding: 8px; + max-width: 300px; +} + +ul { + list-style: disc inside; + padding-left: 0; + max-width: 320px; +} + +li { + margin-bottom: 5px; +} + diff --git a/ejercicio5/index.html b/ejercicio5/index.html index 51c5f8b..b5bd0cd 100644 --- a/ejercicio5/index.html +++ b/ejercicio5/index.html @@ -2,13 +2,18 @@
- +