1 Commits

Author SHA1 Message Date
Juanse Marquez
5f7e970258 Solución ejercicio 1 2026-06-01 18:41:31 -03:00
4 changed files with 12 additions and 66 deletions

View File

@@ -1,26 +1,14 @@
// 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"); const boton = document.querySelector("#boton");
boton.addEventListener("click", (e) => { boton.addEventListener("click", () => {
const nombre = document.querySelector("#nombre").value; const nombre = document.querySelector("#nombre").value;
if (nombre.trim() !== "") { const saludo = document.querySelector("#saludo");
// trim() elimina espacios al inicio y al final, para que un texto
document.getElementById("saludo").textContent = `Hola, ${nombre}!`; // con solo espacios no se considere válido.
if (nombre.trim() === "") {
saludo.textContent = "Por favor, ingresá tu nombre.";
} else { } else {
saludo.textContent = `Hola, ${nombre}!`;
document.getElementById("saludo").textContent = "Por favor, ingresa tu nombre"
} }
}); });

View File

@@ -8,9 +8,10 @@
</head> </head>
<body> <body>
<h1>Ejercicio 1</h1> <h1>Ejercicio 1</h1>
<input type="text" id="nombre" placeholder="Ingresa tu nombre"> <input type="text" id="nombre" placeholder="Tu nombre">
<p id="saludo"></p> <button id="boton">Saludar</button>
<button type="submit" id="boton">Enviar</button> <p id="saludo"></p>
<script src="ejercicio1.js"></script> <script src="ejercicio1.js"></script>
</body> </body>
</html> </html>

View File

@@ -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);

View File

@@ -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>