Compare commits
1 Commits
solucion-e
...
solucion-e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ba0098e540 |
@@ -1,35 +1 @@
|
|||||||
const btnSumar = document.querySelector("#sumar");
|
// Agregar aquí el código javascript
|
||||||
const btnRestar = document.querySelector("#restar");
|
|
||||||
|
|
||||||
function actualizarVista(valor) {
|
|
||||||
const MIN = 0;
|
|
||||||
const MAX = 10;
|
|
||||||
const parrafo = document.querySelector("#contador");
|
|
||||||
parrafo.textContent = valor;
|
|
||||||
|
|
||||||
// Habilitamos o deshabilitamos los botones según el valor actual.
|
|
||||||
// Cuando disabled es true, el botón no responde a clics.
|
|
||||||
btnSumar.disabled = valor === MAX;
|
|
||||||
btnRestar.disabled = valor === MIN;
|
|
||||||
}
|
|
||||||
|
|
||||||
btnSumar.addEventListener("click", () => {
|
|
||||||
// Obtenermos el valor actual
|
|
||||||
let valor = parseInt(document.querySelector('#contador').textContent);
|
|
||||||
// Sumamos 1
|
|
||||||
valor++;
|
|
||||||
// y actualizamos la vista
|
|
||||||
actualizarVista(valor);
|
|
||||||
});
|
|
||||||
|
|
||||||
btnRestar.addEventListener("click", () => {
|
|
||||||
// Obtenermos el valor actual
|
|
||||||
let valor = parseInt(document.querySelector('#contador').textContent);
|
|
||||||
// Restamos 1
|
|
||||||
valor--;
|
|
||||||
// y actualizamos la vista
|
|
||||||
actualizarVista(valor);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Llamamos a actualizarVista al inicio para establecer el estado inicial en 5.
|
|
||||||
actualizarVista(5);
|
|
||||||
|
|||||||
@@ -8,11 +8,6 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Ejercicio 4</h1>
|
<h1>Ejercicio 4</h1>
|
||||||
<p>
|
|
||||||
<button id="restar">Restar</button>
|
|
||||||
<span id="contador">0</span>
|
|
||||||
<button id="sumar">Sumar</button>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<script src="ejercicio4.js"></script>
|
<script src="ejercicio4.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -1 +1,37 @@
|
|||||||
// Agregar aquí el código javascript
|
const paises = [
|
||||||
|
"Argentina", "Brasil", "Chile", "Colombia", "Ecuador",
|
||||||
|
"México", "Paraguay", "Perú", "Uruguay", "Venezuela"
|
||||||
|
];
|
||||||
|
|
||||||
|
const campo = document.querySelector("#filtro");
|
||||||
|
|
||||||
|
function construirLista(items) {
|
||||||
|
const lista = document.querySelector("#lista");
|
||||||
|
// Limpiamos la lista antes de reconstruirla.
|
||||||
|
lista.innerHTML = "";
|
||||||
|
|
||||||
|
for (const pais of items) {
|
||||||
|
const item = document.createElement("li");
|
||||||
|
item.textContent = pais;
|
||||||
|
lista.appendChild(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
campo.addEventListener("input", () => {
|
||||||
|
const texto = campo.value.toLowerCase();
|
||||||
|
|
||||||
|
// Si el campo está vacío, mostramos todos los países.
|
||||||
|
// Si no, filtramos los que incluyan el texto ingresado.
|
||||||
|
// toLowerCase() en ambos lados hace la comparación sin distinguir mayúsculas.
|
||||||
|
if (texto === "") {
|
||||||
|
construirLista(paises);
|
||||||
|
} else {
|
||||||
|
const filtrados = paises.filter(p => p.toLowerCase().includes(texto));
|
||||||
|
// Otra forma, con indexOf:
|
||||||
|
// const filtrados = paises.filter(p => p.toLowerCase().indexOf(texto) > -1);
|
||||||
|
construirLista(filtrados);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Mostramos todos los países al cargar la página.
|
||||||
|
construirLista(paises);
|
||||||
|
|||||||
@@ -8,6 +8,8 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Ejercicio 5</h1>
|
<h1>Ejercicio 5</h1>
|
||||||
|
<input type="text" id="filtro" placeholder="Buscar país...">
|
||||||
|
<ul id="lista"></ul>
|
||||||
|
|
||||||
<script src="ejercicio5.js"></script>
|
<script src="ejercicio5.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Reference in New Issue
Block a user