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!
How 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 July 2026
Contest runs July 1 - 31. Complete challenges to climb the leaderboard!
Only the 31 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.