Notepad can create a small game by saving HTML and JavaScript as an .html file. The browser runs the game; Notepad is where you write and change it. A plain .txt file will only show the code.
This example makes a number-guessing game that works locally in Edge, Chrome, or Firefox. It doesn't need an account, a download, or a web server.
In this guide
Start a plain-text file in Notepad
Open Start, type Notepad, and open the app. Create a new tab or document. Windows 10's older Notepad works too, because the example only needs ordinary text editing.
Copy the whole example into the empty document, including its first and last lines. Keep the punctuation exactly as written. JavaScript uses matching braces, parentheses, and straight quote marks, so a missing character can stop the game.
If your newer Notepad offers formatted and plain-text views, use the plain-text view for editing this code. The HTML tags should stay visible while you're working in Notepad. Their job is to describe the page the browser will display.
The short example is easy to read through. It chooses a number from 1 to 20, counts valid guesses, and tells the player to go higher or lower. New game starts another round without reopening the file.
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Guess the Number</title>
<style>
body{font:1.2rem system-ui;background:#eef3f8;margin:0;padding:24px}
main{max-width:420px;margin:auto;padding:24px;background:white;border-radius:16px}
input,button{font:inherit;padding:10px;margin:8px 0;border:0;border-radius:8px;background:#e4edf6}
button{cursor:pointer;background:#ffe08a}
input:focus-visible,button:focus-visible{outline:0;box-shadow:0 0 0 4px #b8d6f3}
</style>
<main>
<h1>Guess the Number</h1>
<p>Find the whole number from 1 to 20.</p>
<form id="game">
<label for="guess">Your guess</label>
<input id="guess" type="number" min="1" max="20" step="1" required>
<button id="check" type="submit">Check</button>
</form>
<p id="message" aria-live="polite">Enter your first guess.</p>
<button id="restart" type="button">New game</button>
</main>
<script>
const form = document.getElementById('game');
const input = document.getElementById('guess');
const check = document.getElementById('check');
const message = document.getElementById('message');
let answer, attempts;
function newGame() {
answer = Math.floor(Math.random() * 20) + 1;
attempts = 0;
input.value = '';
input.disabled = check.disabled = false;
message.textContent = 'Enter your first guess.';
}
form.addEventListener('submit', function(event) {
event.preventDefault();
const guess = Number(input.value);
if (input.value.trim() === '' || !Number.isInteger(guess) || guess < 1 || guess > 20) {
message.textContent = 'Enter a whole number from 1 to 20.';
return;
}
attempts += 1;
if (guess === answer) {
message.textContent = 'Correct! Guesses used: ' + attempts;
input.disabled = check.disabled = true;
} else {
message.textContent = guess < answer ? 'Try a higher number.' : 'Try a lower number.';
input.select();
}
});
document.getElementById('restart').addEventListener('click', newGame);
newGame();
</script>
</html>
Save the document as HTML rather than TXT
Choose File > Save as. In the dialog, set All files for Save as type. Enter GuessingGame.html as the filename and keep the UTF-8 encoding. Save it in Documents or another folder you can find.

The extension is the part after the final dot. Windows uses it to decide what kind of file you've saved. Microsoft's file extension guide explains how to make extensions visible.
In Windows 11 File Explorer, choose View > Show > File name extensions. On Windows 10, open the View tab and select File name extensions. Check the complete name, not just the file's icon.
A name ending in .html.txt is still a text document. Rename it to remove the final .txt, accept the extension-change prompt, then open it again. Save as type matters because Notepad can otherwise add its usual text extension.
The same naming mistake affects Markdown files created in Notepad. For this game, though, the required extension is HTML, since the browser needs to interpret the page and its script.
Open the file in a browser and play a round
Find GuessingGame.html in File Explorer and double-click it. If Windows opens an editor instead, right-click the file and choose Open with, then select your browser. The browser's address bar should point to the file on your computer.
The page should display Guess the Number, a number field, Check, and New game. Seeing tags such as <main> on the page means the file is being treated as text or its contents weren't saved correctly.
Enter a whole number from 1 to 20 and press Check. An incorrect guess produces a higher-or-lower hint. A correct answer displays the number of guesses used and disables the input and Check button.
Press New game for another round. It clears the input, resets the count, and enables the controls again. The random choice can occasionally be the same number as last time; starting a new round doesn't require it to differ.
Understand the three parts before changing them
HTML supplies the heading, form, number field, and buttons. CSS, inside the style tags, controls their appearance. JavaScript, inside the script tags, chooses the answer and responds when a player submits a guess.
The line containing Math.floor(Math.random() * 20) + 1 picks a whole number from 1 to 20. The script compares your guess with that number and responds with higher, lower, or correct. It counts a guess only after checking that it's valid.
Change the heading or the background color first if you want to personalize the page. Save with Ctrl+S, return to the browser, and refresh. Notepad's saved edits don't appear in an already open page until the browser reloads the file.
For a larger number range, change the 20 in the random-number calculation, the input's maximum, the script's range check, and the messages together. Changing just the heading gives players new rules but keeps the old range.
For a broader introduction to the editor, use Notepad's Windows controls. A game needs the browser's JavaScript support in addition to the text file you write there.
Fix a blank page or a button that does nothing
First check that all the code was copied, especially the script's closing tags. Reopen the HTML file in Notepad to inspect it, save the correction, and refresh the browser. Editing a different copy won't change the file currently open.
If the heading appears but Check doesn't respond, press F12 and select Console in the browser's developer tools. A red syntax error usually identifies missing or mismatched punctuation. Compare that line with the example.
Include the error text and line number when you ask for JavaScript help. If the file won't save, try your Documents folder and ask Microsoft Support about that Notepad save error. Include your Windows version.
The Short Version
Paste the code into Notepad, save it as GuessingGame.html with All files selected, then open the saved HTML file in your browser. Make changes in Notepad, save, and refresh the page to play the updated version.
Checked December 5, 2026.







