feat: implement country search functionality with dynamic results
This commit is contained in:
@@ -1 +1,45 @@
|
|||||||
// Agregar aquí el código javascript
|
// Agregar aquí el código javascript
|
||||||
|
|
||||||
|
const countries = [
|
||||||
|
'Argentina',
|
||||||
|
'Brasil',
|
||||||
|
'Chile',
|
||||||
|
'Colombia',
|
||||||
|
'Ecuador',
|
||||||
|
'Perú',
|
||||||
|
'Uruguay',
|
||||||
|
'Venezuela',
|
||||||
|
'Paraguay',
|
||||||
|
'Bolivia',
|
||||||
|
'Panamá',
|
||||||
|
'Costa Rica',
|
||||||
|
'Cuba',
|
||||||
|
'República Dominicana',
|
||||||
|
'Guatemala',
|
||||||
|
'Honduras',
|
||||||
|
'El Salvador',
|
||||||
|
'Nicaragua',
|
||||||
|
'Puerto Rico',
|
||||||
|
'México',
|
||||||
|
'Estados Unidos',
|
||||||
|
'Canadá',
|
||||||
|
'Guayana',
|
||||||
|
'Surinam',
|
||||||
|
'Guyana Francesa',
|
||||||
|
];
|
||||||
|
|
||||||
|
document.getElementById('search').addEventListener('input', () => {
|
||||||
|
const query = document.getElementById('search').value.toLowerCase();
|
||||||
|
const resultsList = document.getElementById('resultsList');
|
||||||
|
resultsList.innerHTML = '';
|
||||||
|
|
||||||
|
const filteredCountries = countries.filter(country =>
|
||||||
|
country.toLowerCase().includes(query)
|
||||||
|
);
|
||||||
|
|
||||||
|
filteredCountries.forEach(country => {
|
||||||
|
const li = document.createElement('li');
|
||||||
|
li.textContent = country;
|
||||||
|
resultsList.appendChild(li);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -8,7 +8,11 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Ejercicio 5</h1>
|
<h1>Ejercicio 5</h1>
|
||||||
|
<div id="results">
|
||||||
|
<label for="search">Buscar:</label>
|
||||||
|
<input type="text" id="search" name="search">
|
||||||
|
<ul id="resultsList"></ul>
|
||||||
|
</div>
|
||||||
<script src="ejercicio5.js"></script>
|
<script src="ejercicio5.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user