forked from marquez.juan/clase-10-ejercicios-de-repaso
Compare commits
2 Commits
main
...
0a50af5868
| Author | SHA1 | Date | |
|---|---|---|---|
| 0a50af5868 | |||
| 8b5b25c46e |
@@ -1 +1,21 @@
|
|||||||
// Agregar aquí el código javascript
|
// 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");
|
||||||
|
|
||||||
|
// 2. Registro del Event Listener utilizando una función clásica
|
||||||
|
boton.addEventListener("click", function () {
|
||||||
|
|
||||||
|
// 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 {
|
||||||
|
// Caso en que contenga texto válido
|
||||||
|
resultado.textContent = `Hola, ${nombre}!`;
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -8,7 +8,9 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Ejercicio 1</h1>
|
<h1>Ejercicio 1</h1>
|
||||||
|
<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>
|
<script src="ejercicio1.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -1 +1,29 @@
|
|||||||
// Agregar aquí el código javascript
|
// 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>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width">
|
<meta name="viewport" content="width=device-width" />
|
||||||
<title>Ejercicio 2</title>
|
<title>Ejercicio 2</title>
|
||||||
<link rel="stylesheet" href="estilo.css">
|
<link rel="stylesheet" href="estilo.css" />
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Ejercicio 2</h1>
|
<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>
|
<script src="ejercicio2.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user