Computer Science, asked by sakshijangale223, 7 months ago

write a
Program to find the factorial of number
using Javascript​

Answers

Answered by siddharthpkhandelwal
1

Answer:

function factorial(n){

 let answer = 1;

 if (n == 0 || n == 1){

   return answer;

 }else{

   for(var i = n; i >= 1; i--){

     answer = answer * i;

   }

   return answer;

 }  

}

let n = 4;

answer = factorial(n)

console.log("The factorial of " + n + " is " + answer);

Similar questions