Compare commits
1 Commits
solucion-e
...
solucion-e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5f7e970258 |
@@ -1 +1,14 @@
|
|||||||
// Agregar aquí el código javascript
|
const boton = document.querySelector("#boton");
|
||||||
|
|
||||||
|
boton.addEventListener("click", () => {
|
||||||
|
const nombre = document.querySelector("#nombre").value;
|
||||||
|
|
||||||
|
const saludo = document.querySelector("#saludo");
|
||||||
|
// trim() elimina espacios al inicio y al final, para que un texto
|
||||||
|
// con solo espacios no se considere válido.
|
||||||
|
if (nombre.trim() === "") {
|
||||||
|
saludo.textContent = "Por favor, ingresá tu nombre.";
|
||||||
|
} else {
|
||||||
|
saludo.textContent = `Hola, ${nombre}!`;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|||||||
@@ -8,6 +8,9 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Ejercicio 1</h1>
|
<h1>Ejercicio 1</h1>
|
||||||
|
<input type="text" id="nombre" placeholder="Tu nombre">
|
||||||
|
<button id="boton">Saludar</button>
|
||||||
|
<p id="saludo"></p>
|
||||||
|
|
||||||
<script src="ejercicio1.js"></script>
|
<script src="ejercicio1.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -1,22 +1 @@
|
|||||||
// Agregar aquí el código javascript
|
// Agregar aquí el código javascript
|
||||||
const boton = document.querySelector("#agregar");
|
|
||||||
|
|
||||||
boton.addEventListener("click", () => {
|
|
||||||
const campo = document.querySelector("#agregar input");
|
|
||||||
const texto = campo.value.trim();
|
|
||||||
|
|
||||||
const lista = document.querySelector("#lista ul");
|
|
||||||
|
|
||||||
// Si el campo está vacío, no hacemos nada.
|
|
||||||
if (texto === "") return;
|
|
||||||
|
|
||||||
// Creamos el nuevo ítem y lo agregamos a la lista.
|
|
||||||
const item = document.createElement("li");
|
|
||||||
item.textContent = texto;
|
|
||||||
lista.appendChild(item);
|
|
||||||
|
|
||||||
// Limpiamos el campo para que el usuario pueda escribir la próxima tarea.
|
|
||||||
campo.value = "";
|
|
||||||
// Ponemos el cursor nuevamente en el campo:
|
|
||||||
campo.focus();
|
|
||||||
});
|
|
||||||
|
|||||||
@@ -8,16 +8,6 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Ejercicio 2</h1>
|
<h1>Ejercicio 2</h1>
|
||||||
<div id="lista">
|
|
||||||
<h2>Lista de tareas</h2>
|
|
||||||
<ul>
|
|
||||||
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
<div id="agregar">
|
|
||||||
<input type="text" placeholder="Descripción de la nueva tarea">
|
|
||||||
<button type="button">Agregar tarea</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<script src="ejercicio2.js"></script>
|
<script src="ejercicio2.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Reference in New Issue
Block a user