feat: add a greeting button with validation
This commit is contained in:
@@ -1 +1,10 @@
|
|||||||
// Agregar aquí el código javascript
|
// Agregar aquí el código javascript
|
||||||
|
|
||||||
|
document.getElementById('greet').addEventListener('click', () => {
|
||||||
|
const name = document.getElementById('name').value;
|
||||||
|
if (name.trim() === '') {
|
||||||
|
alert('Por favor, ingresa tu nombre.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
document.getElementById('greeting').textContent = `¡Hola, ${name}!`;
|
||||||
|
});
|
||||||
@@ -8,7 +8,10 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Ejercicio 1</h1>
|
<h1>Ejercicio 1</h1>
|
||||||
|
<label for="name">Nombre:</label>
|
||||||
|
<input type="text" id="name" name="name">
|
||||||
|
<button id="greet">Saludar</button>
|
||||||
|
<p id="greeting"></p>
|
||||||
<script src="ejercicio1.js"></script>
|
<script src="ejercicio1.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user