WIP Eventos #4

Open
dalessandro.bruno wants to merge 5 commits from dalessandro.bruno/clase-9-eventos:ejercicios-eventos into main
2 changed files with 33 additions and 1 deletions
Showing only changes of commit 3ccdaea6e9 - Show all commits

View File

@@ -1 +1,32 @@
// Agregar acá el código javascript para los ejercicios
/*
1. Agregar a la página un botón y un párrafo que diga `Botón clickeado 0
veces`. Cada vez que se haga clic en el botón, el texto del párrafo debe
cambiar al mensaje `"Botón clickeado N veces"`, donde N es el número de
veces que se hizo clic.
*/
const boton = document.getElementById("boton");
boton.addEventListener("click", () => {
let contador = parseInt(document.getElementById("cantidad").textContent);
contador = contador + 1;
document.getElementById("cantidad").textContent = contador;
if (contador === 1) {
document.getElementById("descripcionCantidad").textContent = "vez.";
} else {
document.getElementById("descripcionCantidad").textContent = "veces.";
}
})

View File

@@ -9,7 +9,8 @@
<body>
<h1>Clase 9 - Eventos</h1>
<div id="ejercicio-1">
<!-- Agregar acá el código HTML que haga falta para el ejercicio 1 -->
<p>Boton clickeado <span id="cantidad">0</span> <span id="descripcionCantidad">veces.</span></p>
<button id="boton">Haz click aqui</button>
</div>
<hr>
<div id="ejercicio-2">