forked from marquez.juan/clase-10-ejercicios-de-repaso
ejercicio 1: saludo personalizado
This commit is contained in:
@@ -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}!`;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|||||||
@@ -2,13 +2,19 @@
|
|||||||
<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 1</title>
|
<title>Ejercicio 1</title>
|
||||||
<link rel="stylesheet" href="estilo.css">
|
<link rel="stylesheet" href="estilo.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Ejercicio 1</h1>
|
<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>
|
<script src="ejercicio1.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user