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();
|
||||||
|
|||||||
@@ -2,13 +2,17 @@
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Ejercicio 4</title>
|
<title>Ejercicio 4</title>
|
||||||
<link rel="stylesheet" href="estilo.css">
|
<link rel="stylesheet" href="estilo.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Ejercicio 4</h1>
|
<h1>Ejercicio 4</h1>
|
||||||
|
|
||||||
|
<button id="restar">Restar</button>
|
||||||
|
<button id="sumar">Sumar</button>
|
||||||
|
<p>Contador: <span id="valor">0</span></p>
|
||||||
|
|
||||||
<script src="ejercicio4.js"></script>
|
<script src="ejercicio4.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user