Thursday, 26 November 2015

Fizz Buzz Program

Write a program that will print all the numbers from 1 to 100 that will print "FizzBuzz", for numbers that are divisible by both 3 and 5 and print "Fizz" for numbers divisible by 3 and "Buzz" for numbers divisible by 5:



for(var i=1; i<=100; i++) {
    if((i % 3 == 0) && (i % 5 == 0)) {
        document.write("FizzBuzz");
        document.write("
");
    }
    else if(i % 3 == 0) {
         document.write("Fizz");
         document.write("
");
     }
    else if(i % 5 == 0) {
        document.write("Buzz");
     document.write("
");
    }
    
    else {
        document.write(i);
        document.write("
");
    }
}

0 comments:

Post a Comment