Calculator Tools Calculator Tools
Create

Interactive Number Guessing Game

Oct 3, 2025

About this app

Test your number guessing skills with our fun and colorful interactive web app! Try to guess the number in as few attempts as possible.

Interactive Number Guessing Game Number Guessing Game Guess a number between 1 and 100! Guess! Play Again Attempts: 0

Related apps

Put this on your site

Source

                    <html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1">

<title>Interactive Number Guessing Game</title>
<meta name="description" content="Test your number guessing skills with our fun and colorful interactive web app! Try to guess the number in as few attempts as possible." />
<meta name="keywords" content="number guessing game, interactive game, colorful app, fun game, number challenge" />

<!-- Libraries -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.min.js" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.6.0/css/fontawesome.min.css" crossorigin="anonymous">

<script type="text/javascript">
try {
// App Javascript Goes Here. Place your entire script content inside the try block for error handling.
let randomNumber;
let attempts;

document.addEventListener("DOMContentLoaded", function() {
startGame();

document.getElementById("guess-button").addEventListener("click", function() {
const userGuess = parseInt(document.getElementById("user-guess").value);
checkGuess(userGuess);
});

document.getElementById("reset-button").addEventListener("click", startGame);
});

function startGame() {
randomNumber = Math.floor(Math.random() * 100) + 1; // Random number between 1 and 100
attempts = 0;
document.getElementById("attempts").innerText = "Attempts: 0";
document.getElementById("message").innerText = "";
document.getElementById("user-guess").value = "";
document.getElementById("user-guess").focus();
}

function checkGuess(guess) {
attempts++;
document.getElementById("attempts").innerText = "Attempts: " + attempts;

if (guess < randomNumber) {
document.getElementById("message").innerText = "Too low! Try again.";
} else if (guess > randomNumber) {
document.getElementById("message").innerText = "Too high! Try again.";
} else {
document.getElementById("message").innerText = `Congratulations! You guessed it in ${attempts} attempts.`;
}
}
} catch (error) {
throw error;
}
</script>

<style>
body {
background: linear-gradient(135deg, #f3f4f6, #cbd5e1);
color: #344954;
font-family: 'Arial', sans-serif;
}
#main-container {
text-align: center;
margin-top: 50px;
padding: 20px;
background-color: white;
border-radius: 10px;
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}
#guess-section {
margin-top: 20px;
}
h1 {
color: #61dafb;
}
button {
margin: 5px;
}
#message {
margin-top: 15px;
font-weight: bold;
color: #2f855a;
}
</style>
</head>
<body>
<div id="main-container" class="container">
<h1>Number Guessing Game</h1>
<p>Guess a number between 1 and 100!</p>
<div id="guess-section">
<input type="number" id="user-guess" min="1" max="100" class="form-control" placeholder="Enter your guess" required />
<button id="guess-button" class="btn btn-primary">Guess!</button>
<button id="reset-button" class="btn btn-secondary">Play Again</button>
</div>
<p id="attempts">Attempts: 0</p>
<p id="message"></p>
</div>
</body>
</html>