Ad

Write a function that:

  • returns "Fizz" for multiples of 3
  • returns "Buzz" for multiples of 5
  • returns "FizzBuzz" for multiples of both 3 and 5

Any other number should return the number as string.

export function fizzBuzz(input: number): string {
    const output: string = `${input % 3 === 0 ? "Fizz" : ""}${input % 5 === 0 ? "Buzz" : ""}`;
    return output.length > 0 ? output : input.toString(10);
}