Está en la página 1de 2

<!

DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Juego de Adivinanzas</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin: 50px;
}

#output {
font-size: 1.5em;
margin-bottom: 20px;
}

input {
padding: 5px;
font-size: 1em;
}

button {
padding: 8px 16px;
font-size: 1em;
cursor: pointer;
}
</style>
</head>
<body>

<h1>Juego de Adivinanzas</h1>
<p>Adivina el número entre 1 y 100:</p>

<div id="output"></div>
<input type="number" id="guess" placeholder="Tu respuesta">
<button onclick="checkGuess()">Verificar</button>

<script>
// Generar un número aleatorio entre 1 y 100
const randomNumber = Math.floor(Math.random() * 100) + 1;

function checkGuess() {
// Obtener el valor ingresado por el jugador
const userGuess = parseInt(document.getElementById("guess").value);

// Comprobar si la suposición es correcta


if (userGuess === randomNumber) {
document.getElementById("output").innerHTML = "¡Correcto! ¡Has adivinado el
número!";
} else if (userGuess < randomNumber) {
document.getElementById("output").innerHTML = "Incorrecto. Intenta con un
número mayor.";
} else {
document.getElementById("output").innerHTML = "Incorrecto. Intenta con un
número menor.";
}
}
</script>

</body>
</html>

También podría gustarte