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

  1. If n is divisible by 3 and 5, return "FizzBuzz".
  2. If n is divisible by 3 only, return "Fizz".
  3. If n is divisible by 5 only, return "Buzz".
  4. Otherwise, return n as 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

Inputn = 15
Output"FizzBuzz"

Explanation: Divisible by both 3 and 5.

02EXAMPLE 2

Inputn = 7
Output"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
JavaScript
Loading...
5 Hidden

Input Arguments

n15

Expected Output

FizzBuzz

Click RUN to test your solution