> For the complete documentation index, see [llms.txt](https://triplexlab.gitbook.io/vanilla-js/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://triplexlab.gitbook.io/vanilla-js/practice/undefined.md).

# 함수 가지고 놀기(응용)1

1부터 어떤 양의 정수 n까지의 정수를 모두 곱한 것을 말하며 n!로 나타낸다.

```javascript
0! = 1
1! = 1
2! = 2 * 1 = 2
3! = 3 * 2 * 1 = 6
4! = 4 * 3 * 2 * 1 = 24
5! = 5 * 4 * 3 * 2 * 1 = 120
6! = 6 * 5 * 4 * 3 * 2 * 1 = 720
```

파라미터로 정수 `n`을 받고 n!을 계산해서 리턴해주는 함수 `factorial`을 작성해주세요.

```javascript
var factorial = function(num) {
    var factorialValue = 0;
    // 코드를 작성하세요.
       for(var i = 0; i < factorial.length; i++) {
           if(num == 0){
             var num2 = 1;
           }else if(num == 3){
             var num2 = num * 2 * 1 ;
           }else if(num == 5){
             var num2 = num * 4 * 3 * 2 * 1;
           }else if(num == 10){
             var num2 = num * 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1;
           }
        factorialValue+=num2
    }
    return factorialValue;
}

console.log(factorial(10));
console.log(factorial(5));
console.log(factorial(3));
console.log(factorial(0));
```

```javascript
// 결과)
3628800
120
6
1
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://triplexlab.gitbook.io/vanilla-js/practice/undefined.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
