Algorithm


Problem Link : https://www.hackerrank.com/challenges/js10-function/problem

 

Problem Details:

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

Locked stub code in the editor reads a single integer, , from stdin and passes it to a function named factorial.

Constraints

 

Output Format

The function must return the value of .

Sample Input 0

4

Sample Output 0

24

Explanation 0

We return the value of .

 

Code Examples

#1 Code Example with Javascript Programming

Code - Javascript Programming


//Main part
/*
 * Create the function factorial here
 */
function factorial(n) {
    var i    = 1,
        fact = 1;
        
    for( i = 1; i  < = n; i++ ) {
        fact *= i;
    }
    
    return fact;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
4

Output

x
+
cmd
120
Advertisements

Demonstration


Previous
[Solved] Day 8: Dictionaries and Maps solution in Hackerrank - Hacerrank solution C, C++, C#, java, Js, PHP, Python in 30 days of code
Next
[Solved] Day 10: Binary Numbers solution in Hackerrank - Hacerrank solution C, C++, C#, java, Js, PHP, Python & GO in 30 days of code