
Code Logic: The FizzBuzz Test
Code Logic: The FizzBuzz Test
The famous interview question that separates the coding wheat from the chaff!
The Challenge
Alright, code warriors, here’s the legendary FizzBuzz test! Your mission, should you choose to accept it, is to write a program that does the following:
- Prints the numbers from 1 to 100.
- But for multiples of 3, print “Fizz” instead of the number.
- And for multiples of 5, print “Buzz” instead of the number.
- Finally, for numbers which are multiples of both 3 and 5, print “FizzBuzz”.
Sounds simple? That’s what they all say…
A Tiny Hint
Think about using the modulo operator (%). It’s your secret weapon to detect multiples!
The Solution
Behold! The FizzBuzz code in all its glory (JavaScript version):
for (let i = 1; i <= 100; i++) {
let output = '';
if (i % 3 === 0) {
output += 'Fizz';
}
if (i % 5 === 0) {
output += 'Buzz';
}
console.log(output || i);
}
Don't let the code fool you! It's more straightforward than it looks. We loop through numbers 1 to 100. If a number is divisible by 3, we add "Fizz" to the output. If it's divisible by 5, we add "Buzz". And if it's divisible by both, we get "FizzBuzz"! The output || i part is a clever way to print the number if it's not a multiple of 3 or 5.
Brain Check!
Here's the real test... What will the code print for the number 15? Think carefully! Drop your answer in the comments below!




