Skip to content

Commit 7a92dc3

Browse files
lenchen1112ArvinH
andauthored
Functions (#38)
* feat: translation 50% of Functions * feat: translat 100% of Functions * Apply suggestions from code review Co-Authored-By: ArvinH <[email protected]> * Update 1-js/02-first-steps/14-function-basics/article.md Co-Authored-By: ArvinH <[email protected]>
1 parent d458c2c commit 7a92dc3

File tree

9 files changed

+165
-159
lines changed

9 files changed

+165
-159
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
No difference.
1+
沒有不同。
2+

1-js/02-first-steps/14-function-basics/1-if-else-required/task.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ importance: 4
22

33
---
44

5-
# Is "else" required?
5+
# "else" 是否必須?
66

7-
The following function returns `true` if the parameter `age` is greater than `18`.
7+
底下的函式中,若參數 `age` 大於 `18` 時會回傳 `true`
88

9-
Otherwise it asks for a confirmation and returns its result:
9+
否則它會要求確認並回傳結果:
1010

1111
```js
1212
function checkAge(age) {
@@ -21,7 +21,7 @@ function checkAge(age) {
2121
}
2222
```
2323

24-
Will the function work differently if `else` is removed?
24+
若把 `else` 刪掉,此函式是否會以不同方式運作?
2525

2626
```js
2727
function checkAge(age) {
@@ -35,4 +35,5 @@ function checkAge(age) {
3535
}
3636
```
3737

38-
Is there any difference in the behavior of these two variants?
38+
這兩種做法在行為上是否有任何不同?
39+
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
Using a question mark operator `'?'`:
1+
使用問號運算子 `'?'`
22

33
```js
44
function checkAge(age) {
55
return (age > 18) ? true : confirm('Did parents allow you?');
66
}
77
```
88

9-
Using OR `||` (the shortest variant):
9+
使用 OR `||`(最短的做法):
1010

1111
```js
1212
function checkAge(age) {
1313
return (age > 18) || confirm('Did parents allow you?');
1414
}
1515
```
1616

17-
Note that the parentheses around `age > 18` are not required here. They exist for better readabilty.
17+
注意圍繞著 `age > 18` 的括號在此並非必要,它們存在的原因只是為了更佳的可讀性。
18+

1-js/02-first-steps/14-function-basics/2-rewrite-function-question-or/task.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ importance: 4
22

33
---
44

5-
# Rewrite the function using '?' or '||'
5+
# 使用 '?' '||' 改寫函式
66

7-
The following function returns `true` if the parameter `age` is greater than `18`.
7+
底下的函式中,若參數 `age` 大於 `18` 則回傳 `true`
88

9-
Otherwise it asks for a confirmation and returns its result.
9+
否則它要求確認並回傳其結果。
1010

1111
```js
1212
function checkAge(age) {
@@ -18,9 +18,10 @@ function checkAge(age) {
1818
}
1919
```
2020

21-
Rewrite it, to perform the same, but without `if`, in a single line.
21+
改寫它,使其在沒有 `if` 的情況下,以單獨一行就可以達到同樣的操作。
2222

23-
Make two variants of `checkAge`:
23+
寫出兩種 `checkAge` 的不同做法:
24+
25+
1. 使用問號運算子 `?`
26+
2. 使用 OR `||`
2427

25-
1. Using a question mark operator `?`
26-
2. Using OR `||`

1-js/02-first-steps/14-function-basics/3-min/solution.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
A solution using `if`:
1+
使用 `if` 的解法:
22

33
```js
44
function min(a, b) {
@@ -10,12 +10,13 @@ function min(a, b) {
1010
}
1111
```
1212

13-
A solution with a question mark operator `'?'`:
13+
使用問號運算子 `'?'` 的解法:
1414

1515
```js
1616
function min(a, b) {
1717
return a < b ? a : b;
1818
}
1919
```
2020

21-
P.S. In the case of an equality `a == b` it does not matter what to return.
21+
註:在相等的情況 `a == b`,回傳哪一個就不重要了。
22+

1-js/02-first-steps/14-function-basics/3-min/task.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ importance: 1
22

33
---
44

5-
# Function min(a, b)
5+
# 函式 min(a, b)
66

7-
Write a function `min(a,b)` which returns the least of two numbers `a` and `b`.
7+
寫出一個函式 `min(a, b)`,用以回傳 `a` `b` 兩個數值中的最小者。
88

9-
For instance:
9+
舉個例:
1010

1111
```js
1212
min(2, 5) == 2

1-js/02-first-steps/14-function-basics/4-pow/solution.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ if (n < 1) {
1919
alert( pow(x, n) );
2020
}
2121
```
22+

1-js/02-first-steps/14-function-basics/4-pow/task.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@ importance: 4
22

33
---
44

5-
# Function pow(x,n)
5+
# 函式 pow(x, n)
66

7-
Write a function `pow(x,n)` that returns `x` in power `n`. Or, in other words, multiplies `x` by itself `n` times and returns the result.
7+
寫一個函式 `pow(x, n)`,用以回傳 `x` `n` 次方。換句話說,將 `x` 自乘 `n` 次並回傳其結果。
88

99
```js
1010
pow(3, 2) = 3 * 3 = 9
1111
pow(3, 3) = 3 * 3 * 3 = 27
1212
pow(1, 100) = 1 * 1 * ...* 1 = 1
1313
```
1414

15-
Create a web-page that prompts for `x` and `n`, and then shows the result of `pow(x,n)`.
15+
建立一個網頁,分別跳出提示輸入 `x` `n` 的 prompts,並顯示 `pow(x, n)` 的結果。
1616

1717
[demo]
1818

19-
P.S. In this task the function should support only natural values of `n`: integers up from `1`.
19+
註:在本課題中函式應該要只支援自然數 `n`:從 `1` 開始向上數的整數。
20+

0 commit comments

Comments
 (0)