Ad

replaced if statements with ternary operators and build string up so we cover 'fizzbuzz' case implicitly.

Code
Diff
  • using System;
    
    namespace Solution {
    
      class FizzBuzz {
        public static string convert(int input)
            {
                var output = "";
    
                output += (input % 3 == 0) ? "Fizz" : "";
                output += (input % 5 == 0) ? "Buzz" : "";
                output += (string.IsNullOrEmpty(output)) ? input.ToString() : "";
    
                return output;
            }
      }
    }
    • using System;
    • namespace Solution {
    • class FizzBuzz {
    • public static string convert(int input){
    • if (input % 3 == 0 && input % 5 == 0) {
    • return "FizzBuzz";
    • }
    • if (input % 3 == 0) {
    • return "Fizz";
    • }
    • if (input % 5 == 0) {
    • return "Buzz";
    • }
    • return input.ToString();
    • }
    • public static string convert(int input)
    • {
    • var output = "";
    • output += (input % 3 == 0) ? "Fizz" : "";
    • output += (input % 5 == 0) ? "Buzz" : "";
    • output += (string.IsNullOrEmpty(output)) ? input.ToString() : "";
    • return output;
    • }
    • }
    • }