mirror of
https://gitlab.com/tutorial-java-rafa-munoz/tutorial-java-2024-25/LMSGI-2024-25.git
synced 2025-11-09 09:57:39 +01:00
30 lines
1.1 KiB
HTML
30 lines
1.1 KiB
HTML
<!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>
|