forked from marquez.juan/clase-10-ejercicios-de-repaso
Compare commits
1 Commits
f212ceaee5
...
solucion-e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d505e030c2 |
@@ -1,18 +1 @@
|
|||||||
// Agregar aquí el código javascript
|
// Agregar aquí el código javascript
|
||||||
|
|
||||||
// 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."`.
|
|
||||||
|
|
||||||
let saludo = document.querySelector("#saludo");
|
|
||||||
let boton = document.querySelector("#enviar");
|
|
||||||
let form = document.querySelector("form");
|
|
||||||
let nombre = document.querySelector("#input-nombre");
|
|
||||||
|
|
||||||
form.addEventListener("submit", (e) => {
|
|
||||||
e.preventDefault();
|
|
||||||
if (nombre.value.trim() === ""){
|
|
||||||
saludo.textContent = "Por favor, ingresá tu nombre.";
|
|
||||||
} else {saludo.textContent = `Hola ${nombre.value}!`}
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|||||||
@@ -8,13 +8,6 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Ejercicio 1</h1>
|
<h1>Ejercicio 1</h1>
|
||||||
<p>Ingrese su nombre</p>
|
|
||||||
<form action="">
|
|
||||||
<label for="input-nombre"></label>
|
|
||||||
<input type="text" name="input-nombre" id="input-nombre">
|
|
||||||
<button type="submit" id="enviar-form">ver</button>
|
|
||||||
</form>
|
|
||||||
<p id="saludo"></p>
|
|
||||||
|
|
||||||
<script src="ejercicio1.js"></script>
|
<script src="ejercicio1.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -1,21 +1 @@
|
|||||||
// Agregar aquí el código javascript
|
// Agregar aquí el código javascript
|
||||||
|
|
||||||
// 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.
|
|
||||||
|
|
||||||
let input = document.querySelector("input") //almacenamos en variables el boton, el input y la lista
|
|
||||||
let boton = document.querySelector("button");
|
|
||||||
let lista = document.querySelector("ul")
|
|
||||||
|
|
||||||
boton.addEventListener("click", ()=>{ // creamos el listener "click" con la funcion
|
|
||||||
if (!(input.value.trim() === "")){ // si el input NO ESTÁ vacio, continuamos :
|
|
||||||
nuevoLi = document.createElement("li"); //creamos el li ,
|
|
||||||
nuevoLi.textContent = input.value.trim(); // le damos contenido ,
|
|
||||||
lista.appendChild(nuevoLi); // lo anexamos a la lista ,
|
|
||||||
input.value = ""; // y vaciamos el input :)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
// fin
|
|
||||||
@@ -8,13 +8,7 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Ejercicio 2</h1>
|
<h1>Ejercicio 2</h1>
|
||||||
<p>escriba un texto para agregar a la lista</p>
|
|
||||||
<br>
|
|
||||||
<input type="text" name="input" id="input">
|
|
||||||
<button id="boton-agregar">Agregar</button>
|
|
||||||
<br>
|
|
||||||
<ul>
|
|
||||||
</ul>
|
|
||||||
<script src="ejercicio2.js"></script>
|
<script src="ejercicio2.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -1,15 +1 @@
|
|||||||
// Agregar aquí el código javascript
|
// Agregar aquí el código javascript
|
||||||
|
|
||||||
// Crear una lista con al menos seis ítems de cualquier contenido. Al hacer clic
|
|
||||||
// en un ítem, agregarle la clase `"seleccionado"`. Al hacer clic de nuevo sobre
|
|
||||||
// el mismo ítem, quitarle la clase.
|
|
||||||
|
|
||||||
// Usar delegación de eventos, incluyendo un solo listener en la lista, no uno por
|
|
||||||
// ítem.
|
|
||||||
|
|
||||||
let lista = document.querySelector("ul");
|
|
||||||
|
|
||||||
lista.addEventListener("click", (e)=>{
|
|
||||||
e.target.classList.toggle("defensor-elegido"); //usamos el toggle para agregar/sacar la clase defensor-elegido
|
|
||||||
console.log(e.target.classList)
|
|
||||||
})
|
|
||||||
@@ -8,15 +8,7 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Ejercicio 3</h1>
|
<h1>Ejercicio 3</h1>
|
||||||
<p>Defensores convocados</p>
|
|
||||||
<ul>
|
|
||||||
<li class="defensor">Romero</li>
|
|
||||||
<li class="defensor">Senesi</li>
|
|
||||||
<li class="defensor">Tagliafico</li>
|
|
||||||
<li class="defensor">Molina</li>
|
|
||||||
<li class="defensor">Barco</li>
|
|
||||||
<li class="defensor">Martinez</li>
|
|
||||||
</ul>
|
|
||||||
<script src="ejercicio3.js"></script>
|
<script src="ejercicio3.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -1 +1,46 @@
|
|||||||
// Agregar aquí el código javascript
|
const form = document.querySelector("#formulario");
|
||||||
|
|
||||||
|
function mostrarError(id, mensaje) {
|
||||||
|
document.querySelector(id).textContent = mensaje;
|
||||||
|
}
|
||||||
|
|
||||||
|
function limpiarError(id) {
|
||||||
|
document.querySelector(id).textContent = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
form.addEventListener("submit", (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
const nombre = document.querySelector("#nombre").value.trim();
|
||||||
|
const edad = document.querySelector("#edad").value.trim();
|
||||||
|
const password = document.querySelector("#password").value;
|
||||||
|
|
||||||
|
// Limpiamos todos los errores antes de volver a validar.
|
||||||
|
limpiarError("#error-nombre");
|
||||||
|
limpiarError("#error-edad");
|
||||||
|
limpiarError("#error-password");
|
||||||
|
document.querySelector("#exito").textContent = "";
|
||||||
|
|
||||||
|
let valido = true;
|
||||||
|
|
||||||
|
if (nombre === "") {
|
||||||
|
mostrarError("#error-nombre", "El nombre no puede estar vacío.");
|
||||||
|
valido = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (edad === "" || parseInt(edad) < 0 || parseInt(edad) > 100) {
|
||||||
|
mostrarError("#error-edad", "La edad no tiene un formato válido.");
|
||||||
|
valido = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (password.length < 8) {
|
||||||
|
mostrarError("#error-password", "La contraseña debe tener al menos 8 caracteres.");
|
||||||
|
valido = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Solo mostramos el éxito si todos los campos son válidos.
|
||||||
|
if (valido) {
|
||||||
|
document.querySelector("#exito").textContent = "Formulario enviado correctamente.";
|
||||||
|
form.reset(); // reset() limpia todos los campos del formulario
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|||||||
@@ -1,2 +1,6 @@
|
|||||||
/* Agregar el código CSS necesario para el ejercicio */
|
/* Agregar el código CSS necesario para el ejercicio */
|
||||||
|
.error {
|
||||||
|
color: red;
|
||||||
|
font-size: 0.5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,22 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Ejercicio 7</h1>
|
<h1>Ejercicio 7</h1>
|
||||||
|
<form id="formulario">
|
||||||
|
<div>
|
||||||
|
<input type="text" id="nombre" placeholder="Nombre">
|
||||||
|
<span class="error" id="error-nombre"></span>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<input type="number" id="edad" placeholder="Edad">
|
||||||
|
<span class="error" id="error-edad"></span>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<input type="password" id="password" placeholder="Contraseña">
|
||||||
|
<span class="error" id="error-password"></span>
|
||||||
|
</div>
|
||||||
|
<button type="submit">Enviar</button>
|
||||||
|
<p id="exito"></p>
|
||||||
|
</form>
|
||||||
|
|
||||||
<script src="ejercicio7.js"></script>
|
<script src="ejercicio7.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Reference in New Issue
Block a user