Write a function that returns a string according to the FizzBuzz rules:
- For numbers divisible by 3, return "Fizz"
- For numbers divisible by 5, return "Buzz"
- For numbers divisible by both 3 and 5, return "FizzBuzz"
- For any other number, return the number as a string
Examples:
Input: num = 3
Output: "Fizz"
Explanation: 3 is divisible by 3, so return "Fizz"
Input: num = 5
Output: "Buzz"
Explanation: 5 is divisible by 5, so return "Buzz"
Input: num = 15
Output: "FizzBuzz"
Explanation: 15 is divisible by both 3 and 5, so return "FizzBuzz"
Input: num = 7
Output: "7"
Explanation: 7 is not divisible by 3 or 5, so return the number as a string
Apex Code Editor
Welcome to Lightning Challenge!
Create an Account
Sign up to track your progress, earn points, and compete with others. Your solutions will be saved automatically.
Create accountHow It Works
- • Write your solution in the code editor
- • Connect your Salesforce org to test
- • Submit to check if your solution passes
- • Use hints if you get stuck
Contest Alert
🏆 #CodeEveryDay Feb 2026
Contest runs February 1 - 28. Complete challenges to climb the leaderboard!
Points are calculated for challenges completed during the contest period.