From 3016e835c450747e87d065591e884dcf91b2ee95 Mon Sep 17 00:00:00 2001 From: Juanse Marquez Date: Mon, 1 Jun 2026 18:48:38 -0300 Subject: [PATCH] =?UTF-8?q?Soluci=C3=B3n=20ejercicio=204?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ejercicio4/ejercicio4.js | 36 +++++++++++++++++++++++++++++++++++- ejercicio4/index.html | 5 +++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/ejercicio4/ejercicio4.js b/ejercicio4/ejercicio4.js index 6ce9e92..0b7b721 100644 --- a/ejercicio4/ejercicio4.js +++ b/ejercicio4/ejercicio4.js @@ -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); diff --git a/ejercicio4/index.html b/ejercicio4/index.html index f7e70b1..0df777b 100644 --- a/ejercicio4/index.html +++ b/ejercicio4/index.html @@ -8,6 +8,11 @@

Ejercicio 4

+

+ + 0 + +