Factorial of a Number

What is Factorial?

The factorial of a number is the product of all the numbers from 1 to that number. For example,

a factorial of 5 equals 1 * 2 * 3 * 4 * 5 = 120.

Program

var terms = 5,nextTerm = 0, start = 0,prev = 1;
var output = [];
while(start<=terms){
    output.push(nextTerm);
  nextTerm = prev+start;
  prev = start;
  start = nextTerm;
}

console.log(output.toString());

Output

0,1,1,2,3,5″

Pattern Program In JavaScript     Data Types In JavaScript

Back to top button