forked from marquez.juan/clase-10-ejercicios-de-repaso
Compare commits
1 Commits
ccabe13670
...
solucion-e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ba0098e540 |
@@ -1,26 +1 @@
|
|||||||
// Agregar aquí el código javascript
|
// Agregar aquí el código javascript
|
||||||
|
|
||||||
/* Ejercicio 1: Saludo personalizado
|
|
||||||
|
|
||||||
Crear una página con un campo de texto y un botón. Al hacer clic en el botón,
|
|
||||||
leer el valor del campo y mostrar en la página el mensaje `"Hola, [nombre]!"`.
|
|
||||||
Si el campo está vacío, mostrar en su lugar `"Por favor, ingresá tu nombre."`. */
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const boton = document.querySelector("#boton");
|
|
||||||
|
|
||||||
boton.addEventListener("click", (e) => {
|
|
||||||
|
|
||||||
const nombre = document.querySelector("#nombre").value;
|
|
||||||
|
|
||||||
if (nombre.trim() !== "") {
|
|
||||||
|
|
||||||
document.getElementById("saludo").textContent = `Hola, ${nombre}!`;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
document.getElementById("saludo").textContent = "Por favor, ingresa tu nombre"
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
@@ -8,9 +8,7 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Ejercicio 1</h1>
|
<h1>Ejercicio 1</h1>
|
||||||
<input type="text" id="nombre" placeholder="Ingresa tu nombre">
|
|
||||||
<p id="saludo"></p>
|
|
||||||
<button type="submit" id="boton">Enviar</button>
|
|
||||||
<script src="ejercicio1.js"></script>
|
<script src="ejercicio1.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -1,32 +1 @@
|
|||||||
// Agregar aquí el código javascript
|
// Agregar aquí el código javascript
|
||||||
|
|
||||||
/* Ejercicio 2: Lista de tareas simple
|
|
||||||
|
|
||||||
Crear una página con un campo de texto y un botón "Agregar". Cada vez que se
|
|
||||||
haga clic en el botón, agregar el texto del campo como un nuevo ítem en una
|
|
||||||
lista `<ul>`. Después de agregar el ítem, limpiar el campo.
|
|
||||||
|
|
||||||
Si el campo está vacío al hacer clic, no agregar nada. */
|
|
||||||
|
|
||||||
|
|
||||||
function agregar () {
|
|
||||||
|
|
||||||
const comidaNueva = document.getElementById("comidaNueva").value;
|
|
||||||
|
|
||||||
if (comidaNueva.trim() !== "") {
|
|
||||||
|
|
||||||
const nuevoLi = document.createElement("li");
|
|
||||||
|
|
||||||
nuevoLi.textContent = comidaNueva;
|
|
||||||
|
|
||||||
document.getElementById("lista").appendChild(nuevoLi);
|
|
||||||
|
|
||||||
document.getElementById("comidaNueva").value = "";
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
const boton = document.getElementById("botonAgregar")
|
|
||||||
|
|
||||||
boton.addEventListener("click", agregar);
|
|
||||||
@@ -9,18 +9,6 @@
|
|||||||
<body>
|
<body>
|
||||||
<h1>Ejercicio 2</h1>
|
<h1>Ejercicio 2</h1>
|
||||||
|
|
||||||
|
|
||||||
<h2>Comidas tradicionales de Argentina:</h2>
|
|
||||||
<ul id="lista">
|
|
||||||
<li>Asado</li>
|
|
||||||
<li>Empanadas</li>
|
|
||||||
<li>Locro</li>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
<h3>Agregar una comida a la lista</h3>
|
|
||||||
<input type="text" id="comidaNueva" placeholder="Escribí otra comida tradicional">
|
|
||||||
<br>
|
|
||||||
<button id="botonAgregar">Agregar</button>
|
|
||||||
<script src="ejercicio2.js"></script>
|
<script src="ejercicio2.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -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