Objective
Today, we're discussing JavaScript functions. Check out the attached tutorial for more details.
Task
Implement a function named factorial that has one parameter: an integer, . It must return the value of (i.e., factorial).
Input Format
Constraints
- 1 ≤ n ≤ 10
Output Format
The function must return the value of .
Sample Input 0
4
Sample Output 0
24Explanation 0
We return the value of .
Solution
function factorial(n){
var a=1
for(var i=1;i<=n;i++){
a=a*i;
}
return a;
}
Comments
Post a Comment