A simple, fun, and interactive front-end only number guessing game built using HTML, CSS, and JavaScript.
The game randomly selects a secret number between 1 and 20 (inclusive). You have 4 guesses to find it. After each guess, you'll get feedback:
- "Too high!" if your guess is higher than the secret number
- "Too low!" if your guess is lower
- "Congratulations! You win!" if you guess correctly
If you run out of guesses, the game reveals the secret number and you lose.
Perfect for beginners learning JavaScript or anyone looking for a quick browser game!
Your progress is saved directly in your browser using LocalStorage:
- Total games played
- Total games won
These stats persist across sessions — close the tab or browser, come back later, and your record is still there!
- Pure vanilla JavaScript (no external libraries)
- Responsive and clean UI
- Random number generation (1–20)
- 4 guesses per game with real-time feedback
- Win/lose conditions
- Restart game button
- Stats tracking: games played & wins saved via LocalStorage
- Input validation (only numbers 1–20 accepted)
- HTML5
- CSS3 (for styling and layout)
- Vanilla JavaScript (no external libraries)
-
Clone or download this repository:
git clone https://github.com/amirsafa2024/guess-number-game.git
-
Navigate to the project folder:
cd THE-REPO-FOLDER -
Open
index.htmlin your favorite web browser:- Double-click the file, or
- Right-click → Open with → Browser
-
Start guessing!
Feel free to fork this repository and submit pull requests for improvements, such as:
- Better UI/UX design
- Additional features (e.g., difficulty levels, score tracking)
- Bug fixes
Enjoy the game! If you like it, give this repo a ⭐!