Locked lesson.
About this lesson
Exercise files
Download this lesson’s related exercise files.
Let's Build FizzBuzz!.docx58.8 KB Let's Build FizzBuzz! - Solution.docx
59.5 KB
Quick reference
Let's Build FizzBuzz!
FizzBuzz is a popular interview question for coding jobs.
When to use
FizzBuzz is a fun little app to put what we've learned so far to practical use.
Instructions
The idea of fizzbuzz is to print out all numbers between 1 and 100. If a number is divisible by 3, print fizz; if divisible by 5, print buzz, if divisible by 3 and 5, print fizzbuzz.
<?php
$x = 1;
while ($x <= 100) {
if ($x % 3 == 0 && $x % 5 == 0) {
echo "$x FIZZBUZZ!<br/>";
} elseif ($x % 3 == 0) {
echo "$x FIZZ!<br/>";
} elseif ($x % 5 == 0) {
echo "$x BUZZ!<br/>";
} else {
echo "$x<br/>";
}
$x++;
}
?>
Hints & tips
- FizzBuzz is a popular interview question
Lesson notes are only available for subscribers.