Menu
Coddy logo textTech

Challenge: FizzBuzz

Part of the Logic & Flow section of Coddy's Dart journey — lesson 65 of 65.

challenge icon

Challenge

Easy

Create a program that implements the classic FizzBuzz challenge with proper loop structure and conditional logic. This challenge tests your ability to combine loops, conditional statements, and the modulo operator to solve a well-known programming problem.

Your task is to:

  1. Use a for loop to iterate through numbers from 1 to 50 (inclusive)
  2. For each number, apply the following rules in order:
    • If the number is divisible by both 3 and 5, print FizzBuzz
    • If the number is divisible by 3 only, print Fizz
    • If the number is divisible by 5 only, print Buzz
    • If the number is not divisible by 3 or 5, print the number itself
  3. Each output should be on a separate line
  4. Use the modulo operator (%) to check divisibility
  5. Structure your conditional statements using if, else if, and else in the correct order

The first few lines of your output should look like this:

1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz

Remember that the key to solving FizzBuzz correctly is checking for the "both conditions" case (divisible by both 3 and 5) first, before checking the individual conditions. A number is divisible by another number if the remainder when divided by that number equals zero.

Your program should demonstrate proper use of loops for iteration, the modulo operator for divisibility testing, and conditional statements structured in the correct logical order to handle all possible cases.

Try it yourself

void main() {
  // TODO: Write your code below
  // Use a for loop to iterate from 1 to 50
  // Check divisibility using the modulo operator (%)
  // Remember to check for both 3 AND 5 first, then individual conditions
  
  // Print each result on a separate line
}

All lessons in Logic & Flow