> For the complete documentation index, see [llms.txt](https://songeun.gitbook.io/coding-test/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://songeun.gitbook.io/coding-test/lv.0/30.md).

# 짝수의 합

## **문제**

정수 `n`이 주어질 때, `n`이하의 짝수를 모두 더한 값을 return 하도록 solution 함수를 작성해주세요.

***

**제한사항**

0 < `n` ≤ 1000

***

**입출력 예**

| n  | result |
| -- | ------ |
| 10 | 30     |
| 4  | 6      |

***

**입출력 예 설명**

입출력 예 #1

* `n`이 10이므로 2 + 4 + 6 + 8 + 10 = 30을 return 합니다.

입출력 예 #2

* `n`이 4이므로 2 + 4 = 6을 return 합니다.

## 코드

```javascript
function solution(n) {
    let sum = 0;
    for(let i = 2; i <=n; i += 2) {
        sum += i;
    }
    return sum;
}

```
