Ejercicio 1
This commit is contained in:
@@ -1 +1,26 @@
|
|||||||
// Agregar aquí el código javascript
|
// Agregar aquí el código javascript
|
||||||
|
|
||||||
|
/* Ejercicio 1: Saludo personalizado
|
||||||
|
|
||||||
|
Crear una página con un campo de texto y un botón. Al hacer clic en el botón,
|
||||||
|
leer el valor del campo y mostrar en la página el mensaje `"Hola, [nombre]!"`.
|
||||||
|
Si el campo está vacío, mostrar en su lugar `"Por favor, ingresá tu nombre."`. */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const boton = document.querySelector("#boton");
|
||||||
|
|
||||||
|
boton.addEventListener("click", (e) => {
|
||||||
|
|
||||||
|
const nombre = document.querySelector("#nombre").value;
|
||||||
|
|
||||||
|
if (nombre.trim() !== "") {
|
||||||
|
|
||||||
|
document.getElementById("saludo").textContent = `Hola, ${nombre}!`;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
document.getElementById("saludo").textContent = "Por favor, ingresa tu nombre"
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
@@ -8,7 +8,9 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Ejercicio 1</h1>
|
<h1>Ejercicio 1</h1>
|
||||||
|
<input type="text" id="nombre" placeholder="Ingresa tu nombre">
|
||||||
|
<p id="saludo"></p>
|
||||||
|
<button type="submit" id="boton">Enviar</button>
|
||||||
<script src="ejercicio1.js"></script>
|
<script src="ejercicio1.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user