feat(JS): solved ex block 01

This commit is contained in:
Rafa Muñoz
2025-02-24 14:06:10 +01:00
parent 5473730e80
commit 63fecbac6a
7 changed files with 186 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script>
function verificarParImpar() {
// Obtener el valor del input y convertirlo a número
let numero = parseInt(document.getElementById("numero").value);
// Determinar si es par o impar
let mensaje = (numero % 2 === 0) ? "El número es PAR" : "El número es IMPAR";
// Cambiar el color de fondo según si es positivo o negativo
let colorFondo = (numero >= 0) ? "green" : "red";
// Mostrar el resultado y aplicar el color de fondo
let resultadoElemento = document.getElementById("resultado");
resultadoElemento.innerText = mensaje;
resultadoElemento.style.backgroundColor = colorFondo;
resultadoElemento.style.color = "white"; // Asegurar que el texto sea visible
}
</script>
</head>
<body>
<input type="number" id="numero" placeholder="Ingresa un número">
<button onclick="verificarParImpar()">Verificar</button>
<p id="resultado"></p>
</body>
</html>