forked from marquez.juan/clase-10-ejercicios-de-repaso
ejercicio 4: contador con limite
This commit is contained in:
@@ -1 +1,29 @@
|
||||
// Agregar aquí el código javascript
|
||||
const restarBtn = document.getElementById('restar');
|
||||
const sumarBtn = document.getElementById('sumar');
|
||||
const valorSpan = document.getElementById('valor');
|
||||
|
||||
let contador = 0;
|
||||
const LIMITE_MIN = 0;
|
||||
const LIMITE_MAX = 10;
|
||||
|
||||
function actualizarEstado() {
|
||||
valorSpan.textContent = contador;
|
||||
restarBtn.disabled = contador <= LIMITE_MIN;
|
||||
sumarBtn.disabled = contador >= LIMITE_MAX;
|
||||
}
|
||||
|
||||
restarBtn.addEventListener('click', () => {
|
||||
if (contador > LIMITE_MIN) {
|
||||
contador -= 1;
|
||||
actualizarEstado();
|
||||
}
|
||||
});
|
||||
|
||||
sumarBtn.addEventListener('click', () => {
|
||||
if (contador < LIMITE_MAX) {
|
||||
contador += 1;
|
||||
actualizarEstado();
|
||||
}
|
||||
});
|
||||
|
||||
actualizarEstado();
|
||||
|
||||
Reference in New Issue
Block a user