Js Program

Javascript Program.

 

  1. Factorial of a number.
  2. Binary Gap In Javascript.
  3. Pattern Program In JavaScript.
  4. String Program In Javascript.
  5. Factorial of a Number.
  6. Check whether a string is a Pangram or not.
  7. JavaScript Program To Count The Frequency Of Given Character In String.
  8. Find the Missing Number In JavaScript.
  9. Find the maximum value in an array in JavaScript.
  10. JavaScript Program To Check Whether a String is Palindrome or Not.
  11. Fizz Buzz Program In JavaScript.

Description:

Write a program that prints the numbers from 1 to 100. But for multiples of three, print “Fizz” instead of the number, and for the multiples of five, print “Buzz”. For numbers that are multiples of both three and five, print “FizzBuzz”.

Approach 1:

function fizzbuzz(n){
    for(let i=1;i<=n;i++){     
       if(i % 15 == 0){
            console.log('FizzBuzz')
        } else if(i % 5 == 0){
            console.log('Buzz')
        } else if(i % 3 == 0){
            console.log('Fizz')
        }else{
            console.log(i);
        }
    }
}

fizzbuzz(15);

Approach 2:

function fizzbuzz(n){
    for(let i=1;i<=n;i++){
        let output = '';
        if(i % 3 == 0) output+= 'Fizz';
        if(i % 5 == 0) output+= 'Buzz';
        console.log(output || i)       
    }
}
fizzbuzz(15);

 

Back to top button