1 Commits

Author SHA1 Message Date
Juanse Marquez
3016e835c4 Solución ejercicio 4 2026-06-01 18:48:38 -03:00
6 changed files with 41 additions and 72 deletions

View File

@@ -1,26 +1 @@
// 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"
}
});

View File

@@ -8,9 +8,7 @@
</head>
<body>
<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>
</body>
</html>

View File

@@ -1,32 +1 @@
// 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);

View File

@@ -9,18 +9,6 @@
<body>
<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>
</body>
</html>

View File

@@ -1 +1,35 @@
// Agregar aquí el código javascript
const btnSumar = document.querySelector("#sumar");
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);

View File

@@ -8,6 +8,11 @@
</head>
<body>
<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>
</body>