2 Commits

Author SHA1 Message Date
Bruno Dalessandro
ccabe13670 Ejercicio 2 2026-05-28 12:07:25 -03:00
Bruno Dalessandro
9f57950a7b Ejercicio 1 2026-05-28 11:22:31 -03:00
7 changed files with 73 additions and 25 deletions

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,11 +1 @@
const lista = document.querySelector("#lista"); // Agregar aquí el código javascript
// Un solo listener en la lista, no uno por ítem (delegación de eventos).
lista.addEventListener("click", (e) => {
// Verificamos que el clic fue sobre un <li>. Si fue sobre otro elemento,
// retornamos sin hacer nada.
if (e.target.tagName !== "LI") return;
// toggle agrega la clase si no la tiene, y la quita si ya la tenía.
e.target.classList.toggle("seleccionado");
});

View File

@@ -1,5 +1,2 @@
.seleccionado { /* Agregar el código CSS necesario para el ejercicio */
background-color: yellow;
font-weight: bold;
}

View File

@@ -9,15 +9,6 @@
<body> <body>
<h1>Ejercicio 3</h1> <h1>Ejercicio 3</h1>
<ul id="lista">
<li>Elemento 1</li>
<li>Elemento 2</li>
<li>Elemento 3</li>
<li>Elemento 4</li>
<li>Elemento 5</li>
<li>Elemento 6</li>
</ul>
<script src="ejercicio3.js"></script> <script src="ejercicio3.js"></script>
</body> </body>
</html> </html>