Javascript Function Creation calculate factorial

Description

Javascript Function Creation calculate factorial

function factorial(number) { 
   let product = 1; 
   for (let i = number; i >= 1; --i) { 
      product *= i; /*w  w  w .  jav  a  2s  .c o  m*/
   } 
   return product; 
} 

console.log(factorial(4)); // displays 24 
console.log(factorial(5)); // displays 120 
console.log(factorial(10)); // displays 3628800 



PreviousNext

Related