forked from marquez.juan/clase-9-eventos
Compare commits
2 Commits
ddefc238dc
...
c95ca3ed74
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c95ca3ed74 | ||
|
|
3ccdaea6e9 |
47
clase-9.js
47
clase-9.js
@@ -1 +1,48 @@
|
|||||||
// Agregar acá el código javascript para los ejercicios
|
// 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.";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
2. Agregar un campo de texto a la página. A medida que el usuario escribe,
|
||||||
|
mostrar en tiempo real la cantidad de caracteres ingresados debajo del campo.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
const inputTexto = document.getElementById("texto");
|
||||||
|
|
||||||
|
inputTexto.addEventListener("input", () => {
|
||||||
|
|
||||||
|
let cantidad = inputTexto.value.length;
|
||||||
|
|
||||||
|
document.getElementById("cantidadCaracteres").textContent = cantidad;
|
||||||
|
})
|
||||||
10
index.html
10
index.html
@@ -9,11 +9,17 @@
|
|||||||
<body>
|
<body>
|
||||||
<h1>Clase 9 - Eventos</h1>
|
<h1>Clase 9 - Eventos</h1>
|
||||||
<div id="ejercicio-1">
|
<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>
|
</div>
|
||||||
<hr>
|
<hr>
|
||||||
<div id="ejercicio-2">
|
<div id="ejercicio-2">
|
||||||
<!-- Agregar acá el código HTML que haga falta para el ejercicio 2 -->
|
<input type="text" id="texto">
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Cantidad de caracteres:
|
||||||
|
<span id="cantidadCaracteres">0</span>
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<hr>
|
<hr>
|
||||||
<div id="ejercicio-3">
|
<div id="ejercicio-3">
|
||||||
|
|||||||
Reference in New Issue
Block a user