Compare commits
2 Commits
solucion-e
...
ccabe13670
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ccabe13670 | ||
|
|
9f57950a7b |
@@ -1 +1,26 @@
|
|||||||
// Agregar aquí el código javascript
|
// 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");
|
||||||
|
|
||||||
|
boton.addEventListener("click", (e) => {
|
||||||
|
|
||||||
|
const nombre = document.querySelector("#nombre").value;
|
||||||
|
|
||||||
|
if (nombre.trim() !== "") {
|
||||||
|
|
||||||
|
document.getElementById("saludo").textContent = `Hola, ${nombre}!`;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
document.getElementById("saludo").textContent = "Por favor, ingresa tu nombre"
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
@@ -8,7 +8,9 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Ejercicio 1</h1>
|
<h1>Ejercicio 1</h1>
|
||||||
|
<input type="text" id="nombre" placeholder="Ingresa tu nombre">
|
||||||
|
<p id="saludo"></p>
|
||||||
|
<button type="submit" id="boton">Enviar</button>
|
||||||
<script src="ejercicio1.js"></script>
|
<script src="ejercicio1.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -1 +1,32 @@
|
|||||||
// 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);
|
||||||
@@ -9,6 +9,18 @@
|
|||||||
<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>
|
||||||
|
|||||||
@@ -1,35 +1 @@
|
|||||||
const btnSumar = document.querySelector("#sumar");
|
// Agregar aquí el código javascript
|
||||||
const btnRestar = document.querySelector("#restar");
|
|
||||||
|
|
||||||
function actualizarVista(valor) {
|
|
||||||
const MIN = 0;
|
|
||||||
const MAX = 10;
|
|
||||||
const parrafo = document.querySelector("#contador");
|
|
||||||
parrafo.textContent = valor;
|
|
||||||
|
|
||||||
// Habilitamos o deshabilitamos los botones según el valor actual.
|
|
||||||
// Cuando disabled es true, el botón no responde a clics.
|
|
||||||
btnSumar.disabled = valor === MAX;
|
|
||||||
btnRestar.disabled = valor === MIN;
|
|
||||||
}
|
|
||||||
|
|
||||||
btnSumar.addEventListener("click", () => {
|
|
||||||
// Obtenermos el valor actual
|
|
||||||
let valor = parseInt(document.querySelector('#contador').textContent);
|
|
||||||
// Sumamos 1
|
|
||||||
valor++;
|
|
||||||
// y actualizamos la vista
|
|
||||||
actualizarVista(valor);
|
|
||||||
});
|
|
||||||
|
|
||||||
btnRestar.addEventListener("click", () => {
|
|
||||||
// Obtenermos el valor actual
|
|
||||||
let valor = parseInt(document.querySelector('#contador').textContent);
|
|
||||||
// Restamos 1
|
|
||||||
valor--;
|
|
||||||
// y actualizamos la vista
|
|
||||||
actualizarVista(valor);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Llamamos a actualizarVista al inicio para establecer el estado inicial en 5.
|
|
||||||
actualizarVista(5);
|
|
||||||
|
|||||||
@@ -8,11 +8,6 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Ejercicio 4</h1>
|
<h1>Ejercicio 4</h1>
|
||||||
<p>
|
|
||||||
<button id="restar">Restar</button>
|
|
||||||
<span id="contador">0</span>
|
|
||||||
<button id="sumar">Sumar</button>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<script src="ejercicio4.js"></script>
|
<script src="ejercicio4.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Reference in New Issue
Block a user