Javascript Recursive Function Calculate Factorial

Description

Javascript Recursive Function Calculate Factorial

console.log( "Factorials of 1 to 10" );
for ( let i = 0; i <= 10; i++ ) 
   console.log( i + "!:" + factorial( i ) );

// Recursive definition of function factorial
function factorial( number )                  
{                                             
   if ( number <= 1 )  // base case           
      return 1;                               
   else                                       
      return number * factorial( number - 1 );
} // end function factorial                                             



PreviousNext

Related