ejercicio 1: saludo personalizado

This commit is contained in:
2026-05-28 13:04:44 -03:00
parent 610d2530dd
commit 3f3d33484c
2 changed files with 20 additions and 2 deletions

View File

@@ -1 +1,13 @@
// Agregar aquí el código javascript
const nombreInput = document.getElementById('nombre');
const saludarBtn = document.getElementById('saludar');
const mensajeP = document.getElementById('mensaje');
saludarBtn.addEventListener('click', () => {
const nombre = nombreInput.value.trim();
if (nombre === '') {
mensajeP.textContent = 'Por favor, ingresá tu nombre.';
} else {
mensajeP.textContent = `Hola, ${nombre}!`;
}
});

View File

@@ -2,13 +2,19 @@
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ejercicio 1</title>
<link rel="stylesheet" href="estilo.css">
</head>
<body>
<h1>Ejercicio 1</h1>
<label for="nombre">Ingresa tu nombre:</label>
<input id="nombre" type="text" placeholder="Tu nombre">
<button id="saludar">Saludar</button>
<p id="mensaje"></p>
<script src="ejercicio1.js"></script>
</body>
</html>