Compare commits
1 Commits
solucion-e
...
solucion-e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3016e835c4 |
@@ -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>
|
||||||
|
|||||||
@@ -1 +1,35 @@
|
|||||||
// Agregar aquí el código javascript
|
const btnSumar = document.querySelector("#sumar");
|
||||||
|
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,6 +8,11 @@
|
|||||||
</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