Skip to content

Commit 7975906

Browse files
dev-dainViolet-Bora-Lee
authored andcommitted
기본 연산자와 수학 과제 번역
[기본 연산자와 수학] 수정 #601
1 parent 31a3024 commit 7975906

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
1-
The reason is that prompt returns user input as a string.
1+
의도한 대로 덧셈이 되지 않는 이유는 prompt 함수가 사용자 입력을 문자열로 반환하기 때문입니다.
22

3-
So variables have values `"1"` and `"2"` respectively.
3+
그래서 프롬프트 창에서 입력한 변수들은 각각 문자열인 `"1"``"2"`가 되죠.
44

55
```js run
6-
let a = "1"; // prompt("First number?", 1);
7-
let b = "2"; // prompt("Second number?", 2);
6+
let a = "1"; // prompt("덧셈할 첫 번째 숫자를 입력해주세요.", 1);
7+
let b = "2"; // prompt("덧셈할 두 번째 숫자를 입력해주세요.", 2);
88

99
alert(a + b); // 12
1010
```
1111

12-
What we should to is to convert strings to numbers before `+`. For example, using `Number()` or prepending them with `+`.
12+
예시가 제대로 동작하게 하려면 덧셈 연산 `+`가 수행되기 전에 문자열을 숫자로 변환해야 합니다. 이때 `Number()`를 사용하거나 변수 앞에 `+`를 붙여줄 수 있습니다.
1313

14-
For example, right before `prompt`:
14+
아래 코드에선 `prompt` 함수 바로 앞에서 문자열을 숫자로 변환했습니다.
1515

1616
```js run
17-
let a = +prompt("First number?", 1);
18-
let b = +prompt("Second number?", 2);
17+
let a = +prompt("덧셈할 첫 번째 숫자를 입력해주세요.", 1);
18+
let b = +prompt("덧셈할 두 번째 숫자를 입력해주세요.", 2);
1919

2020
alert(a + b); // 3
2121
```
2222

23-
Or in the `alert`:
23+
아래 코드에선 `alert` 함수 안에서 문자열을 숫자로 변환해 보았습니다.
2424

2525
```js run
26-
let a = prompt("First number?", 1);
27-
let b = prompt("Second number?", 2);
26+
let a = prompt("덧셈할 첫 번째 숫자를 입력해주세요.", 1);
27+
let b = prompt("덧셈할 두 번째 숫자를 입력해주세요.", 2);
2828

2929
alert(+a + +b); // 3
3030
```
3131

32-
Using both unary and binary `+` in the latest code. Looks funny, doesn't it?
32+
코드 한 줄 안에서 단항, 이항 `+` 연산자를 한꺼번에 쓰니 조금 웃겨 보이네요.

1-js/02-first-steps/08-operators/4-fix-prompt/task.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ importance: 5
22

33
---
44

5-
# Fix the addition
5+
# 덧셈 고치기
66

7-
Here's a code that asks the user for two numbers and shows their sum.
7+
아래 코드는 사용자에게 숫자 2개를 입력받은 다음 그 합을 보여줍니다.
88

9-
It works incorrectly. The output in the example below is `12` (for default prompt values).
9+
그런데 의도한 대로 예시가 동작하지 않습니다. 프롬프트 창에 세팅한 기본값을 수정하지 않은 경우 덧셈의 결과는 `12`가 됩니다.
1010

11-
Why? Fix it. The result should be `3`.
11+
왜 그럴까요? 예시가 제대로 동작하도록 코드를 수정해 보세요. 결과는 `3`이 되어야 합니다.
1212

1313
```js run
14-
let a = prompt("First number?", 1);
15-
let b = prompt("Second number?", 2);
14+
let a = prompt("덧셈할 첫 번째 숫자를 입력해주세요.", 1);
15+
let b = prompt("덧셈할 두 번째 숫자를 입력해주세요.", 2);
1616

1717
alert(a + b); // 12
18-
```
18+
```

0 commit comments

Comments
 (0)