Fizz Buzz Test using javascript

Fizz Buzz

Print the numbers from 1 to 100.

Multiples of three print “Fizz” with the number and for the multiples of five print “Buzz” with the number.

If number is multiples of both three and five display “FizzBuzz” and number.

const printNumber = () => {

    let test = '';
 
   for ( let i = 0 ; i <=100; i++ ){
      if ( i%15 === 0 ){
        test +="FizzBuzz " + i + " \n ";
      } else if ( i%3 === 0 ) {
        test +="Fizz " + i + " \n ";
      } else if ( i%5 === 0 ){
        test +="Buzz " + i + " \n ";
      } 
    }
 
    return test;

 }
    console.log(printNumber());

Leave a Comment

Your email address will not be published. Required fields are marked *