<?php echo "¡Hola, Mundo!"; ?>
<?php $num1 = 5; $num2 = 10; $suma = $num1 + $num2; echo "La suma es: " . $suma; ?>
<!DOCTYPE html> <html lang="es"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Juego de Adivinar el Número</title> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <style> body { font-family: Arial, sans-serif; text-align: center; margin-top: 50px; } input, button { padding: 10px; font-size: 16px; margin: 5px; } .result { margin-top: 20px; font-weight: bold; } </style> </head> <body> <h1>Juego de Adivinar el Número</h1> <p>Adivina el número entre 1 y 100:</p> <input type="number" id="guess" placeholder="Ingresa tu número" min="1" max="100"> <button id="checkBtn">Comprobar</button> <button id="resetBtn">Limpiar</button> <div class="result"></div> <script> $(document).ready(function() { var secretNumber; var attempts; function startGame() { secretNumber = Math.floor(Math.random() * 100) + 1; attempts = 0; $(".result").text(""); $("#checkBtn").prop("disabled", false); } // Iniciar el juego al cargar la página startGame(); // Comprobar el número $("#checkBtn").click(function() { var userGuess = parseInt($("#guess").val()); attempts++; if (isNaN(userGuess) || userGuess < 1 || userGuess > 100) { $(".result").text("Por favor, ingresa un número válido entre 1 y 100."); } else if (userGuess < secretNumber) { $(".result").text("El número es más grande. Intentos: " + attempts); } else if (userGuess > secretNumber) { $(".result").text("El número es más pequeño. Intentos: " + attempts); } else { $(".result").text("¡Felicidades! Adivinaste el número en " + attempts + " intentos."); $("#checkBtn").prop("disabled", true); } }); // Limpiar el campo de entrada y reiniciar el juego $("#resetBtn").click(function() { $("#guess").val(""); // Limpiar el campo de texto startGame(); // Reiniciar el juego }); }); </script> </body> </html>
Adivina el número entre 1 y 100: