[#1] KoreanCoding 101: Basic math (기초 수학)
Tags: beginners, javascript, tutorial, programming
Published: 2023-05-07 00:57:53

**Let's start with a short announcement:** A new post for this series will be published every Friday, and depending on the complexity of the challenges, I'll aim to cover around 2-4 of them.

Now, let's get into it! 💫

Do you enjoy math? If not, don't worry! The math we'll be covering today is something that most of us encounter in our daily lives.

## Vocabulary

**Nouns:**  
덧셈 - addition  
뺄셈 - subtraction  
곱셈 - multiplication  
나눗셈 - division  
나머지 - remainder (modulo)  
합 - sum, total  
차 - difference  
곱 - product (multiplication)  
정수 - integer (a whole number, e.g. 3)  
분수 - fraction (a part of a whole, e.g. 0.5)  
몫 - quotient (the integer part of a division)  
함수 - function  
매개변수 - parameter  
제한사항 - constraints  
입출력 예 - input-output examples  
입출력 예 설명 - explanation of input-output examples

**Verbs:**  
2에 1을 더하다 - to add 1 to 2  
2에 1을 추가하다 - to add 1 to 2  
2에 1을 빼다 - to subtract 1 from 2  
2에 1를 곱하다 - to multiply 2 by 1  
1을 2로 나누다 - to divide 1 by 2

**Phrases**:  
**\[something\]을/를 return 하도록 solution 함수를 완성해주세요.**  
Complete the solution function to return \[something\].

**정수 num1과 num2가 주어질 때...**  
given two integers num1 and num2...

**num1과 num2의 합**  
the sum of num1 and num2

**num1에서 num2를 뺀 값**  
the value obtained by subtracting num2 from num1

**num1과 num2를 곱한 값**  
the value obtained by multiplying num1 by num2

**num1을 num2로 나눈 값**  
the value obtained by dividing num1 by num2

**num1을 num2로 나눈 몫**  
the result of dividing num1 by num2

**num1를 num2로 나눈 나머지**  
the remainder (modulo) of dividing num1 by num2

## Challenges

### [두 수의 합](https://school.programmers.co.kr/learn/courses/30/lessons/120802)

**Description**

> <mark>정수</mark> `num1`과 `num2`가 주어질 때, `num1`과 `num2`의 <mark>합</mark>을 return하도록 solution 함수를 완성해주세요.
> 
> ***제한사항***
> 
> * \-50,000 ≤ `num1` ≤ 50,000
>     
> * \-50,000 ≤ `num2` ≤ 50,000
>     
> 
> **입출력 예**
> 
> | num1 | num2 | result |
> | --- | --- | --- |
> | 2 | 3 | 5 |
> | 100 | 2 | 102 |
> 
> **입출력 예 설명**
> 
> 입출력 예 #1
> 
> * `num1`이 2이고 `num2`가 3이므로 2 + 3 = 5를 return합니다.
>     
> 
> 입출력 예 #2
> 
> * `num1`이 100이고 `num2`가 2이므로 100 + 2 = 102를 return합니다.
>     

**Description:**  
When we look at the description of this challenge, we can already see some familiar words and phrases. Typically, coding challenges start by outlining the parameters that will be provided.

**두 수의 합**  
The sum of two numbers

**정수** `num1`**과** `num2`**가 주어질 때**  
Given two integers `num1` and `num2`,

`num1`**과** `num2`**의 합을 return하도록 solution 함수를 완성해주세요.**  
complete the `solution` function to return the sum of `num1` and `num2`.

**제한사항 (constraints):**  
The constraints section of the challenge informs us that both `num1` and `num2` can have values ranging from -50,000 to 50,000.

**입출력 예 (input-output examples):**  
Examples are a valuable tool for understanding the challenge description. In this case, we are provided with two input-output examples, which illustrate the given integers and the expected output from the solution function.

When `num1 = 2` and `num2 = 3` result should be `5`.

**입출력 예 설명 (explanation of input-output examples):**  
This section provides a detailed explanation of how the input-output process works for each example. For instance, in the given example where `num1 = 2` and `num2 = 3`, we can read:

`num1`**이 2이고** `num2`**가 3이므로 2 + 3 = 5를 return합니다.**  
Since `num1` is 2 and `num2` is 3, the function returns 2 + 3 = 5.

**JavaScript Solution**

And now we know exactly what to do and we can complete our solution function.

```javascript
function solution(num1, num2) {
    return num1 + num2
}
```

---

### [두 수의 차](https://school.programmers.co.kr/learn/courses/30/lessons/120803)

**Description**

> <mark>정수</mark> `num1`과 `num2`가 주어질 때, `num1`에서 `num2`를 <mark>뺀 값</mark>을 return하도록 solution 함수를 완성해주세요.
> 
> **제한사항**
> 
> * \-50000 ≤ `num1` ≤ 50000
>     
> * \-50000 ≤ `num2` ≤ 50000
>     
> 
> **입출력 예**
> 
> | num1 | num2 | result |
> | --- | --- | --- |
> | 2 | 3 | \-1 |
> | 100 | 2 | 98 |
> 
> **입출력 예 설명**
> 
> 입출력 예 #1
> 
> * `num1`이 2이고 `num2`가 3이므로 2 - 3 = -1을 return합니다.
>     
> 
> 입출력 예 #2
> 
> * `num1`이 100이고 `num2`가 2이므로 100 - 2 = 98을 return합니다.
>     

**Description:**  
This challenge is pretty similar to the last one, so let's dive straight into it!

**두 수의 차**  
The difference between the two numbers

**정수** `num1`**과** `num2`**가 주어질 때,**  
Given two integers `num1` and `num2`,

`num1`**에서** `num2`**를 뺀 값을 return하도록 solution 함수를 완성해주세요.**  
complete the `solution` function to return the value obtained by subtracting `num2` from `num1`.

**제한사항 (constraints):**  
The constraints section of the challenge informs us that both `num1` and `num2` can have values ranging from -50,000 to 50,000.

**입출력 예 (input-output examples):**  
When `num1 = 2` and `num2 = 3` result should be `-1`.

**입출력 예 설명 (explanation of input-output examples):**  
Based on the example #1:

`num1`**이 2이고** `num2`**가 3이므로 2 - 3 = -1을 return합니다.**  
Since `num1` is 2 and `num2` is 3, the function returns 2 - 3 = -1.

**JavaScript Solution**

```javascript
function solution(num1, num2) {
    return num1 - num2
}
```

---

### [두 수의 곱](https://school.programmers.co.kr/learn/courses/30/lessons/120804)

**Description**

> <mark>정수</mark> `num1`, `num2`가 <mark>매개변수</mark> 주어집니다. `num1`과 `num2`를 <mark>곱한 값</mark>을 return 하도록 solution 함수를 완성해주세요.
> 
> **제한사항**
> 
> * 0 ≤ `num1` ≤ 100
>     
> * 0 ≤ `num2` ≤ 100
>     
> 
> **입출력 예**
> 
> | num1 | num2 | result |
> | --- | --- | --- |
> | 3 | 4 | 12 |
> | 27 | 19 | 513 |
> 
> **입출력 예 설명**
> 
> 입출력 예 #1
> 
> * `num1`이 3, `num2`가 4이므로 3 \* 4 = 12를 return합니다.
>     
> 
> 입출력 예 #2
> 
> * `num1`이 27, `num2`가 19이므로 27 \* 19 = 513을 return합니다.
>     

**Description:**

**두 수의 곱**  
The product of two numbers

**정수** `num1`**,** `num2`**가 매개변수 주어집니다.**  
Integers `num1`, `num2` are given as parameters.

`num1`**과** `num2`**를 곱한 값을 return 하도록 solution 함수를 완성해주세요.**  
Complete the `solution` function to return the value obtained by multiplying `num1` by `num2`.

**제한사항 (constraints):**

The constraints section of the challenge informs us that both `num1` and `num2` can have values ranging from 0 to 100.

**입출력 예 (input-output examples):**

When `num1 = 3` and `num2 = 4` result should be `12`.

**입출력 예 설명 (explanation of input-output examples):**

Based on the example #1:

`num1`**이 3,** `num2`**가 4이므로 3 \* 4 = 12를 return합니다.**  
Since `num1` is 3 and `num2` is 4, the function returns 3 \* 4 = 12.

**JavaScript Solution**

```javascript
function solution(num1, num2) {
    return num1 * num2
}
```

---

### [두 수의 나눗셈](https://school.programmers.co.kr/learn/courses/30/lessons/120806)

**Description**

> <mark>정수</mark> `num1`과 `num2`가 <mark>매개변수로</mark> 주어질 때, `num1`을 `num2`로 나<mark>눈 값</mark>에 1,000을 곱한 후 <mark>정수 부분</mark>을 return 하도록 solution 함수를 완성해주세요.
> 
> **제한사항**
> 
> * 0 &lt; `num1` ≤ 100
>     
> * 0 &lt; `num2` ≤ 100
>     
> 
> **입출력 예**
> 
> | num1 | num2 | result |
> | --- | --- | --- |
> | 3 | 2 | 1500 |
> | 7 | 3 | 2333 |
> | 1 | 16 | 62 |
> 
> **입출력 예 설명**
> 
> 입출력 예 #1
> 
> * `num1`이 3, `num2`가 2이므로 3 / 2 = 1.5에 1,000을 곱하면 1500이 됩니다.
>     
> 
> 입출력 예 #2
> 
> * `num1`이 7, `num2`가 3이므로 7 / 3 = 2.33333...에 1,000을 곱하면 2333.3333.... 이 되며, 정수 부분은 2333입니다.
>     
> 
> 입출력 예 #3
> 
> * `num1`이 1, `num2`가 16이므로 1 / 16 = 0.0625에 1,000을 곱하면 62.5가 되며, 정수 부분은 62입니다.
>     

**Description:**

**두 수의 나눗셈**  
The division of two numbers

**정수** `num1`**과** `num2`**가 매개변수로 주어질 때,**  
Integers `num1` and `num2` are given as parameters,

`num1`**을** `num2`**로 나눈 값에 1,000을 곱한 후 정수 부분을 return 하도록 solution 함수를 완성해주세요.**  
First divide `num1` by `num2` and then multiply the resulting value by 1000. To complete the `solution` function, the returned value should always be an integer.

**제한사항 (constraints):**

The constraints section of the challenge informs us that both `num1` and `num2` can have values ranging from 0 to 100.

**입출력 예 (input-output examples):**

Example #1:  
When `num1 = 3` and `num2 = 2` result should be `1500`.

Example #2:  
When `num1 = 7` and `num2 = 3` result should be `2333`.

**입출력 예 설명 (explanation of input-output examples):**

Based on the example #1:

`num1`**이 3,** `num2`**가 2이므로 3 / 2 = 1.5에 1,000을 곱하면 1500이 됩니다.**  
Since `num1` is 3 and `num2` is 2, 3 / 2 = 1.5 multiplied by 1,000 is 1500.

Based on the example #2:

`num1`**이 7,** `num2`**가 3이므로 7 / 3 = 2.33333...에 1,000을 곱하면 2333.3333.... 이 되며, 정수 부분은 2333입니다.**  
Since `num1` is 7 and `num2` is 3, 7/3 = 2.33333... Multiplied by 1,000 it is 2333.333... The integer part is 2333.

**JavaScript Solution**

In this challenge, simply dividing and multiplying will not be enough since it will give us a repeating decimal when we are required to return just the integer. To return the correct solution, we can wrap `(num1/num2)*1000` in `Math.floor()`, which will return the largest integer that is less than or equal to a given number.

```javascript
function solution(num1, num2) {
    return Math.floor((num1/num2) * 1000)
}
```

---

### [나머지 구하기](https://school.programmers.co.kr/learn/courses/30/lessons/120810)

**Description**

> 정수 `num1`, `num2`가 <mark>매개변수</mark>로 주어질 때, `num1`를 `num2`로 나눈 <mark>나머지</mark>를 return 하도록 solution 함수를 완성해주세요.
> 
> **제한사항**
> 
> * 0 &lt; `num1` ≤ 100
>     
> * 0 &lt; `num2` ≤ 100
>     
> 
> **입출력 예**
> 
> | num1 | num2 | result |
> | --- | --- | --- |
> | 3 | 2 | 1 |
> | 10 | 5 | 0 |
> 
> **입출력 예 설명**
> 
> 입출력 예 #1
> 
> * `num1`이 3, `num2`가 2이므로 3을 2로 나눈 나머지 1을 return 합니다.
>     
> 
> 입출력 예 #2
> 
> * `num1`이 10, `num2`가 5이므로 10을 5로 나눈 나머지 0을 return 합니다.
>     

**Description:**

**나머지 구하기**  
Finding the rest

**정수** `num1`**,** `num2`**가 매개변수로 주어질 때,**  
Given two integers `num1` and `num2`,

`num1`**를** `num2`**로 나눈 나머지를 return 하도록 solution 함수를 완성해주세요.**  
Complete the `solution` function to return the remainder (modulo) of `num1` by `num2`.

**제한사항 (constraints):**

The constraints section of the challenge informs us that both `num1` and `num2` can have values ranging from 0 to 100.

**입출력 예 (input-output examples):**

When `num1 = 3` and `num2 = 2` result should be `1`.

**입출력 예 설명 (explanation of input-output examples):**

Based on the example #1:

`num1`**이 3,** `num2`**가 2이므로 3을 2로 나눈 나머지 1을 return 합니다.**  
Since `num1` is 3 and `num2` is 2, 3 is divided by 2 and the remainder is 1.

**JavaScript Solution**

If you don't remember how the remainder works, you can [read all about it here](https://www.cuemath.com/numbers/remainder/).  
We will use the % symbol in our `solution` function, as it represents the remainder in computer languages.

```javascript
function solution(num1, num2) {
    return num1 % num2
}
```

---

### [몫 구하기](https://school.programmers.co.kr/learn/courses/30/lessons/120805)

**Description**

> 정수 `num1`, `num2`가 <mark>매개변수로</mark> 주어질 때, `num1`을 `num2`로 <mark>나눈 몫</mark>을 return 하도록 solution 함수를 완성해주세요.
> 
> **제한사항**
> 
> * 0 &lt; `num1` ≤ 100
>     
> * 0 &lt; `num2` ≤ 100
>     
> 
> **입출력 예**
> 
> | num1 | num2 | result |
> | --- | --- | --- |
> | 10 | 5 | 2 |
> | 7 | 2 | 3 |
> 
> **입출력 예 설명**
> 
> 입출력 예 #1
> 
> * `num1`이 10, `num2`가 5이므로 10을 5로 나눈 몫 2를 return 합니다.
>     
> 
> 입출력 예 #2
> 
> * `num1`이 7, `num2`가 2이므로 7을 2로 나눈 몫 3을 return 합니다.
>     

**Description:**

**몫 구하기**  
Finding quotient (the integer part of a division)

**정수** `num1`**,** `num2`**가 매개변수로 주어질 때,**   
Integers `num1`, `num2` are given as parameters,

`num1`**을** `num2`**로 나눈 몫을 return 하도록 solution 함수를 완성해주세요.**  
Complete the `solution` function by returning the integer part of a division of `num1` by `num2`.

**제한사항 (constraints):**

The constraints section of the challenge informs us that both `num1` and `num2` can have values ranging from 0 to 100.

**입출력 예 (input-output examples):**

When `num1 = 10` and `num2 = 5` result should be `2`.

**입출력 예 설명 (explanation of input-output examples):**

For example #1:

`num1`**이 10,** `num2`**가 5이므로 10을 5로 나눈 몫 2를 return 합니다.**  
Since num1 is 10 and num2 is 5, 10 divided by 5 returns the quotient of 2.

**JavaScript Solution**

Here again, since some of the divisions will give us a repeating decimal. To return just an integer, we can simply use `Math.floor()`.

```javascript
function solution(num1, num2) {
    return Math.floor(num1/num2)
}
```

## Wrap-up

Thank you for following along with this lesson! I hope you found it helpful. Remember, **it's important to take things at your own pace and gradually build your skills** when it comes to solving coding challenges, especially if you are also learning a new language. Building a strong technical Korean foundation is essential for tackling more complex challenges with ease.

Next week, we'll dive into topics that go beyond basic math, such as if/else statements, booleans, ternary operators, and more! I look forward to continuing this learning journey with you.

In the meantime, I hope you all have a fantastic weekend!

I'll see you next Friday!