FizzBuzz(JS)


  • 0
    T

    var fizzBuzz = function(n) {
    let currentNum;
    let arr = [];
    for(let i=1;i<=n;i++){
    if(i%3==0&&i%5!=0){
    currentNum ="Fizz";
    }

        if(i%3!=0&&i%5==0){
            currentNum ='Buzz';
        }
        
        if(i%3==0&&i%5==0){
            currentNum ='FizzBuzz';
        }
        
        if(i%3!=0&&i%5!=0){
            currentNum =''+i;
        }  
        arr.push("\n\t\""+currentNum+"\"");
    }
    console.log('['+arr+'\n]');
    

    };

    fizzBuzz(0);


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.