Javascript Program.
- Factorial of a number.
- Binary Gap In Javascript.
- Pattern Program In JavaScript.
- String Program In Javascript.
- Factorial of a Number.
- Check whether a string is a Pangram or not.
- JavaScript Program To Count The Frequency Of Given Character In String.
- Find the Missing Number In JavaScript.
- Find the maximum value in an array in JavaScript.
- JavaScript Program To Check Whether a String is Palindrome or Not.
- 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);