feat(JS): first examples

This commit is contained in:
Rafa Muñoz
2025-02-18 23:19:42 +01:00
parent 17d0563011
commit 5473730e80
2 changed files with 53 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <!-- el charset iso-8859-1 significa "español" -->
<script>
// Crea un formulario con un input y un botón. Al hacer clic, muestra el nombre y edad ingresados en un div.
function mostrarMensaje() {
let nombre = document.getElementById("nombre").value;
let edad = document.getElementById("edad").value;
document.getElementById("resultado").innerHTML = 'Hola, ' + nombre + '. Tienes ' + edad + ' años.';
}
</script>
</head>
<body>
<input type="text" id="nombre" placeholder="Tu nombre">
<input type="number" id="edad" placeholder="Tu edad">
<button onclick="mostrarMensaje()">Enviar</button>
<div id="resultado"></div>
</body>
</html>

View File

@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<!-- el charset iso-8859-1 significa "español" -->
<script>
// Muestra en un p el área de un círculo con un radio ingresado por el usuario.
const PI = 3.1416;
function calcularArea() {
let radio = document.getElementById("radio").value;
let area = PI * radio * radio;
document.getElementById("area").innerText = `Área: ${area}`;
} </script>
</head>
<body>
<input type="number" id="radio" placeholder="Ingresa el radio">
<button onclick="calcularArea()">Calcular Área</button>
<p id="area"></p>
</body>
</html>