diff --git a/ejercicio4/ejercicio4.js b/ejercicio4/ejercicio4.js index 6ce9e92..d8a9023 100644 --- a/ejercicio4/ejercicio4.js +++ b/ejercicio4/ejercicio4.js @@ -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(); diff --git a/ejercicio4/index.html b/ejercicio4/index.html index f7e70b1..dcac1b6 100644 --- a/ejercicio4/index.html +++ b/ejercicio4/index.html @@ -2,13 +2,17 @@ - + Ejercicio 4

Ejercicio 4

+ + +

Contador: 0

+