Number Guess
by PlasmaMeteor4358 lines1.4 KB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Number Guess</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 400px;
margin: 60px auto;
text-align: center;
color: white;
background-color: #111; /* Added so white text is visible */
}
input, button {
padding: 8px 12px;
font-size: 16px;
color: white;
background-color: #222;
border: 1px solid #555;
}
</style>
</head>
<body>
<h1>Guess the Number (1–100)</h1>
<input type="number" id="guessInput" min="1" max="100">
<button onclick="checkGuess()">Guess</button>
<p id="message"></p>
<p id="tries"></p>
<script>
const secret = Math.floor(Math.random() * 100) + 1;
let tries = 0;
function checkGuess() {
const guess = Number(document.getElementById("guessInput").value);
const msg = document.getElementById("message");
const triesEl = document.getElementById("tries");
if (!guess || guess < 1 || guess > 100) {
msg.textContent = "Enter a number from 1 to 100.";
return;
}
tries++;
triesEl.textContent = "Guesses: " + tries;
if (guess < secret) {
msg.textContent = "Too low!";
} else if (guess > secret) {
msg.textContent = "Too high!";
} else {
msg.textContent = "You got it in " + tries + " tries!";
}
}
</script>
</body>
</html>Game Source: Number Guess
Creator: PlasmaMeteor43
Libraries: none
Complexity: moderate (58 lines, 1.4 KB)
The full source code is displayed above on this page.
Remix Instructions
To remix this game, copy the source code above and modify it. Add a ARCADELAB header at the top with "remix_of: number-guess-plasmameteor43" to link back to the original. Then publish at arcadelab.ai/publish.