Fizz Buzz Implementation | Set 2 | Function to generate FizzBuzz sequence ; Stores count of multiples of 3 and 5 respectively ; Iterate from 1 to N ; Increment count3 by 1 ; Increment count5 by 1 ; Initialize a boolean variable to check if none of the condition matches ; Check if the value of count3 is equal to 3 ; Reset count3 to 0 , and set flag as True ; Check if the value of count5 is equal to 5 ; Reset count5 to 0 , and set flag as True ; If none of the condition matches ; Driver Code
function fizzBuzz ( N ) { let count3 = 0 ; let count5 = 0 ; for ( let i = 1 ; i <= N ; i ++ ) { count3 ++ ; count5 ++ ; let flag = false ; if ( count3 == 3 ) { document . write ( " " ) ; count3 = 0 ; flag = true ; } if ( count5 == 5 ) { document . write ( " " ) ; count5 = 0 ; flag = true ; } if ( ! flag ) { document . write ( i ) ; } document . write ( " " ) ; } } let N = 15 ; fizzBuzz ( N ) ;