Compare commits
2 Commits
solucion-e
...
0a50af5868
| Author | SHA1 | Date | |
|---|---|---|---|
| 0a50af5868 | |||
| 8b5b25c46e |
@@ -1,14 +1,21 @@
|
||||
const boton = document.querySelector("#boton");
|
||||
// Agregar aquí el código javascript
|
||||
// 1. Selección de los elementos del DOM
|
||||
const inputNombre = document.querySelector("#campo-nombre");
|
||||
const boton = document.querySelector("#boton-saludo");
|
||||
const resultado = document.querySelector("#mensaje-resultado");
|
||||
|
||||
boton.addEventListener("click", () => {
|
||||
const nombre = document.querySelector("#nombre").value;
|
||||
// 2. Registro del Event Listener utilizando una función clásica
|
||||
boton.addEventListener("click", function () {
|
||||
|
||||
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.";
|
||||
// 3. Obtención y limpieza del valor del campo de texto
|
||||
const nombre = inputNombre.value.trim();
|
||||
|
||||
// 4. Estructura condicional para validar el contenido
|
||||
if (nombre === "") {
|
||||
// Caso en que el campo esté vacío
|
||||
resultado.textContent = "Por favor, ingresá tu nombre.";
|
||||
} else {
|
||||
saludo.textContent = `Hola, ${nombre}!`;
|
||||
// Caso en que contenga texto válido
|
||||
resultado.textContent = `Hola, ${nombre}!`;
|
||||
}
|
||||
});
|
||||
@@ -8,10 +8,9 @@
|
||||
</head>
|
||||
<body>
|
||||
<h1>Ejercicio 1</h1>
|
||||
<input type="text" id="nombre" placeholder="Tu nombre">
|
||||
<button id="boton">Saludar</button>
|
||||
<p id="saludo"></p>
|
||||
|
||||
<input type="text" id="campo-nombre" placeholder="Ingresá tu nombre">
|
||||
<button id="boton-saludo">Saludar</button>
|
||||
<p id="mensaje-resultado"></p>
|
||||
<script src="ejercicio1.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1 +1,29 @@
|
||||
// Agregar aquí el código javascript
|
||||
// 1. Selección de los elementos del DOM mediante sus identificadores
|
||||
const inputItem = document.getElementById("input-item");
|
||||
const btnAgregar = document.getElementById("btn-agregar");
|
||||
const listaContenedor = document.getElementById("lista-contenedor");
|
||||
|
||||
// 2. Registro del escuchador de eventos para el clic del botón
|
||||
btnAgregar.addEventListener("click", function () {
|
||||
|
||||
// 3. Captura y limpieza de espacios en blanco del valor actual del input
|
||||
const textoItem = inputItem.value.trim();
|
||||
|
||||
// 4. Validación: si la cadena está vacía, se interrumpe la ejecución
|
||||
if (textoItem === "") {
|
||||
return;
|
||||
}
|
||||
|
||||
// 5. Creación de un nuevo elemento de lista (<li>) en memoria
|
||||
const nuevoLi = document.createElement("li");
|
||||
|
||||
// 6. Asignación del texto validado al contenido del nuevo elemento
|
||||
nuevoLi.textContent = textoItem;
|
||||
|
||||
// 7. Inserción del nuevo elemento como hijo del contenedor <ul>
|
||||
listaContenedor.appendChild(nuevoLi);
|
||||
|
||||
// 8. Restablecimiento del campo de texto a una cadena vacía
|
||||
inputItem.value = "";
|
||||
});
|
||||
@@ -1,14 +1,16 @@
|
||||
<!DOCTYPE html>
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width">
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
<title>Ejercicio 2</title>
|
||||
<link rel="stylesheet" href="estilo.css">
|
||||
<link rel="stylesheet" href="estilo.css" />
|
||||
</head>
|
||||
<body>
|
||||
<h1>Ejercicio 2</h1>
|
||||
|
||||
<input type="text" id="input-item" placeholder="Escribe un nuevo ítem" />
|
||||
<button id="btn-agregar">Agregar</button>
|
||||
<ul id="lista-contenedor"></ul>
|
||||
<script src="ejercicio2.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user