SHARE
TWEET

Untitled

a guest Oct 23rd, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function fizzBuzz(n){
  2.     let output = [];
  3.  
  4.     if(n <= 0){
  5.         return "Invalid";
  6.     }
  7.     else {
  8.         for(let number = 1; number <= n; number++) {
  9.             if( number%5 === 0 && number%3 === 0 ){
  10.                 output.push("FizzBuzz");
  11.             }
  12.             else if( number % 5 === 0 ){
  13.                 output.push("Buzz");
  14.             }
  15.             else if( number % 3 === 0 ){
  16.                 output.push("Fizz");
  17.             }
  18.             else {
  19.                 output.push(number);
  20.             }
  21.         }
  22.         return output.join("\n");
  23.     }
  24. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top