A modern, interactive FizzBuzz game built with HTML, CSS, and JavaScript. This project demonstrates the implementation of FizzBuzz using DOM manipulation instead of the traditional string concatenation method, with a beautiful summer-themed UI and comprehensive code explanations.
This repository contains:
- 🎮 1 Interactive FizzBuzz Game - Play and learn the classic programming challenge
- 🌍 4 Real-World Application Demos - See how modulo and pattern matching are used in practical applications:
- Date & Time Filtering
- Database Categorization
- Recommendation Systems
- Real-World Use Cases
FizzBuzz is a classic programming challenge where you count from 1 to a chosen number, but with special rules:
- Divisible by 3 → Say "Fizz"
- Divisible by 5 → Say "Buzz"
- Divisible by both 3 AND 5 → Say "FizzBuzz"
- Otherwise → Display the number
Example: 1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16...
- 🎨 Summer-themed UI with vibrant lime, yellow, and orange colors
- 📱 Responsive design that works on desktop and mobile devices
- 🔄 Custom modal instead of browser's native
prompt()function - 📑 Expandable tabs with "How to Play" and "Code Explanation" sections
- 🎯 Input validation with maximum limit of 10,000 to prevent performance issues
- 🧹 Clear button to reset both input and results
- 💻 Comprehensive code explanations comparing different approaches
- ♿ Accessible with proper word wrapping and contrast
- Open
index.htmlin your web browser - Click on "🎮 Game Guide & Code Explanation" to learn how to play
- Enter a number between 1 and 10,000
- Click "Generate FizzBuzz" to see the results
- Use the clear button (✕) inside the input to reset everything
This project demonstrates two different methods for displaying FizzBuzz results:
let text = "";
for (let i = 1; i <= answer; i++) {
if (i % 3 === 0 && i % 5 === 0) {
text += "<span style='color:#ff0000'> FizzBuzz, i = " + i + "</span>" + "<br />";
}
// ... more conditions
}
document.getElementById('results').innerHTML = text;Pros:
- Simple and straightforward
- Easy to understand for beginners
- Can build HTML quickly in one string
Cons:
- Security risk:
innerHTMLcan execute malicious code (XSS vulnerability) - Harder to maintain and style
- Inline styles mixed with logic
- Less flexible for dynamic interactions
for (let i = 1; i <= answer; i++) {
const resultItem = document.createElement('div');
resultItem.className = 'result-item';
if (i % 3 === 0 && i % 5 === 0) {
resultItem.textContent = 'FizzBuzz';
resultItem.classList.add('fizzbuzz');
}
// ... more conditions
resultsDiv.appendChild(resultItem);
}Pros:
- ✅ More secure: No XSS vulnerabilities (uses
textContent) - ✅ Better separation: CSS classes separate styling from logic
- ✅ More maintainable: Easier to update and modify
- ✅ Better performance: Only updates specific elements
- ✅ More flexible: Easy to add event listeners, animations, etc.
- ✅ Modern approach: Industry best practice
Cons:
- Slightly more code
- Requires understanding of DOM API
- More verbose for simple cases
Instead of using the browser's native prompt() modal (which blocks the UI and looks outdated), this project uses an HTML input field with type="number" which automatically provides:
- Up/down arrow buttons (spinner controls) to increment/decrement
- Built-in number validation
- Keyboard support (arrow keys can also change the value)
- Mobile-friendly numeric keypad on touch devices
The for loop iterates through each number from 1 to the user's input:
let i = 1: Start counting from 1 (initialization)i <= answer: Continue as long as i is less than or equal to the answer (condition)i++: Increment i by 1 after each iteration (increment)
Why start at 1? FizzBuzz traditionally starts from 1, not 0, because it's more intuitive for users and counting typically starts at 1.
The modulus operator returns the remainder after division:
6 % 3 = 0(6 divided by 3 equals 2 with remainder 0)7 % 3 = 1(7 divided by 3 equals 2 with remainder 1)10 % 5 = 0(10 divided by 5 equals 2 with remainder 0)
When remainder is 0, it means the number is evenly divisible! So i % 3 === 0 means "is i divisible by 3?"
This project uses === (strict equality) instead of == (loose equality) because:
===checks both value AND type (no type coercion)==can cause unexpected behavior due to type conversion===is more predictable and is considered best practice
Example: 0 === 0 is true, but 0 == "0" is also true (unwanted type conversion). With ===, 0 === "0" is false (correct - different types).
FizzBuzz Game/
├── index.html # Main FizzBuzz game
├── style.css # Game styling
├── script.js # Game logic
├── README.md # This file
├── LICENSE # MIT License
├── 1-Date-Time-Filtering/ # Real-world example 1
│ ├── index.html
│ ├── style.css
│ └── script.js
├── 2-Database-Categorization/ # Real-world example 2
│ ├── index.html
│ ├── style.css
│ └── script.js
├── 3-Recommendation-Systems/ # Real-world example 3
│ ├── index.html
│ ├── style.css
│ └── script.js
└── 4-Real-World-Use-Cases/ # Real-world example 4
├── index.html
├── style.css
└── script.js
- Summer Color Scheme: Vibrant lime green, yellow, and orange gradients
- Smooth Animations: Expand/collapse transitions and hover effects
- Custom Scrollbars: Thin, styled scrollbars matching the theme
- Responsive Grid: Results displayed in a flexible grid layout
- Color-Coded Results: Different colors for numbers, Fizz, Buzz, and FizzBuzz
- Input validation (1-10,000 range)
- XSS protection using
textContentinstead ofinnerHTML - Real-time button state management
- Maximum limit to prevent performance issues
- HTML5: Semantic structure
- CSS3: Modern styling with gradients, animations, and flexbox/grid
- JavaScript (ES6+): DOM manipulation, event handling, and game logic
This project is licensed under the MIT License - see the LICENSE file for details.
You are free to:
- ✅ Use the code for personal or commercial projects
- ✅ Modify and adapt the code
- ✅ Distribute the code
- ✅ Use it in private or public projects
Under the condition that:
- You include the original copyright notice and license
This is an open-source project, completely free to use and modify!
Created as a learning project to demonstrate modern JavaScript practices and DOM manipulation techniques.
- Inspired by the classic FizzBuzz programming challenge
- Built to compare different implementation approaches
- Designed with accessibility and user experience in mind
This repository includes 4 interactive demos that showcase how the core concepts from FizzBuzz (modulo operator, conditional logic, pattern matching) are used in real-world applications. Each demo is a fully functional example you can run in your browser:
- Date & Time Filtering - See how modulo is used for scheduling and time-based categorization
- Database Categorization - Learn about batch processing, data partitioning, and category classification
- Recommendation Systems - Explore A/B testing, load balancing, and content similarity (Netflix/YouTube style)
- Real-World Use Cases - Discover applications in E-commerce, Social Media, Gaming, and System Administration
While FizzBuzz itself is primarily a programming exercise, the core concepts it teaches are used extensively in real-world applications:
The modulo operator is commonly used for:
- Day of week calculations:
day % 7to determine weekday patterns - Scheduling systems: Finding recurring events (every 3rd day, every 5th week)
- Time-based categorization: Grouping data by time intervals
// Example: Show items every 3 days
if (dayNumber % 3 === 0) {
showSpecialOffer();
}- Batch processing: Processing items in groups (every Nth record)
- Data partitioning: Distributing data across multiple servers using
id % serverCount - Category classification: Grouping items by patterns (e.g., every 5th item gets special treatment)
-- Example: Categorize products
SELECT
CASE
WHEN product_id % 3 = 0 THEN 'Category A'
WHEN product_id % 5 = 0 THEN 'Category B'
ELSE 'Standard'
END AS category
FROM products;While companies like Netflix and YouTube don't use FizzBuzz directly, they use similar pattern-matching logic:
- Content similarity algorithms: Finding items with similar characteristics
- User behavior patterns: Identifying users with similar viewing habits
- A/B testing: Dividing users into groups using modulo:
user_id % 2for A/B splits - Load balancing: Distributing requests across servers using
request_id % server_count
E-commerce:
- Showing special offers every Nth customer
- Rotating featured products
- Discount eligibility based on order number patterns
Social Media:
- Feed algorithms that show content in patterns
- Notification batching (every 3rd notification gets priority)
- User segmentation for targeted content
Gaming:
- Spawn rates for items/enemies
- Event scheduling (special events every 5th day)
- Loot drop patterns
System Administration:
- Server rotation for load balancing
- Backup scheduling (backup every Nth day)
- Log rotation and cleanup
The FizzBuzz algorithm teaches:
- ✅ Modulo operator (%): Essential for pattern recognition and cyclic operations
- ✅ Conditional logic: Core to all programming decisions
- ✅ Multiple condition checking: Understanding precedence and logic flow
- ✅ Iteration: Processing collections of data efficiently
These skills translate directly to:
- Building recommendation engines
- Creating filtering systems
- Implementing scheduling algorithms
- Designing categorization systems
Netflix/YouTube-style systems use similar pattern-matching concepts for:
- Content recommendation: Finding similar videos/movies based on patterns
- User clustering: Grouping users with similar behavior patterns
- A/B testing: Using modulo to split users into test groups
- Cache distribution: Using
content_id % cache_serversto distribute content
Example Pattern:
// Similar to FizzBuzz logic - categorizing content
function categorizeContent(contentId) {
if (contentId % 15 === 0) return 'Premium Featured';
if (contentId % 3 === 0) return 'Trending';
if (contentId % 5 === 0) return 'Recommended';
return 'Standard';
}Enjoy playing FizzBuzz! 🎉