The Ternary Fizz
HardAcc. 75.9%
+40 XP 20
Compact Legend
The "FizzBuzz" puzzle is the industry standard for basic logical thinking. Usually, it is solved with several if statements. However, a true master can condense this entire logic into a single, elegant string of ternary operators.
The Rules
- If
nis divisible by 3 and 5, return "FizzBuzz". - If
nis divisible by 3 only, return "Fizz". - If
nis divisible by 5 only, return "Buzz". - Otherwise, return
nas a string (e.g., "7").
The Ultimate Constraint
You must solve this using strictly one line of code inside your function (a single return statement). No if, no else, and no curly braces are allowed in the logic!
01EXAMPLE 1
Input
n = 15Output
"FizzBuzz"Explanation: Divisible by both 3 and 5.
02EXAMPLE 2
Input
n = 7Output
"7"Explanation: Not divisible by 3 or 5, returned as string.
Constraints
- Use strictly one return statement.
- Use nested ternary operators (? :).
- Handle the string conversion for the default case.
Control FlowConditionalsOperators
JavaScriptSystem handles I/O — write your function only
Loading...
5 Hidden
Input Arguments
n15
Expected Output
FizzBuzz
Click RUN to test your solution