fizzBuzz

    0

    0

    YusifHasanov

    The following code defines a function called fizzBuzz, which takes an integer input parameter n. The fizzBuzz function will create an array called arr, and for each integer in the input parameter n, it will check if the input integer is divisible by 3 and 5. If the input integer is divisible by 3, then the arr array will contain the string "FizzBuzz." If the input integer is divisible by 5, then the arr array will contain the string "Fizz." If the input integer is not divisible by 3 and 5, then the arr array will contain the string representation of the input integer. Finally, the fizzBuzz function returns the arr array.

    const fizzBuzz = (n) => {
      let arr = [];
      for (i = 1; i <= n; i++) {
        if (i % 3 === 0 && i % 5 === 0) arr.push("FizzBuzz")
        else if (i % 3 === 0) arr.push("Fizz")
        else if (i % 5 === 0) arr.push("Buzz")
        else arr.push(i.toString())
    
      }
      return arr;
    };
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.