Skip to content

Commit cf20841

Browse files
authored
Merge pull request #13 from lenchen1112/1-02-04
Variables
2 parents 9a69fc1 + 75f8fb8 commit cf20841

File tree

7 files changed

+146
-144
lines changed

7 files changed

+146
-144
lines changed

1-js/02-first-steps/04-variables/1-hello-variables/solution.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
In the code below, each line corresponds to the item in the task list.
1+
底下的程式碼中,每一行都代表著課題列表中的一項。
22

33
```js run
4-
let admin, name; // can declare two variables at once
4+
let admin, name; // 可以一次宣告兩個變數
55

66
name = "John";
77

1-js/02-first-steps/04-variables/1-hello-variables/task.md

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

33
---
44

5-
# Working with variables
5+
# 使用變數
66

7-
1. Declare two variables: `admin` and `name`.
8-
2. Assign the value `"John"` to `name`.
9-
3. Copy the value from `name` to `admin`.
10-
4. Show the value of `admin` using `alert` (must output "John").
7+
1. 宣告兩個變數:`admin` `name`
8+
2. 將值 `"John"` 賦予 `name`
9+
3. `name` 中將值複製給 `admin`
10+
4. 使用 `alert` 顯示 `admin` 的值 (一定會輸出 "John")

1-js/02-first-steps/04-variables/2-declare-variables/solution.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
1-
## The variable for our planet
1+
## 代表我們星球的變數
22

3-
That's simple:
3+
這很簡單:
44

55
```js
66
let ourPlanetName = "Earth";
77
```
88

9-
Note, we could use a shorter name `planet`, but it might be not obvious what planet it refers to. It's nice to be more verbose. At least until the variable isNotTooLong.
9+
注意我們也可用更短的名字 `planet`,但它可能不夠清楚說明代表是哪個星球。有著更多細節是好的,至少在變數 `沒變得太長` 之前。
1010

11-
## The name of the current visitor
11+
## 現在使用者的名字
1212

1313
```js
1414
let currentUserName = "John";
1515
```
1616

17-
Again, we could shorten that to `userName` if we know for sure that the user is current.
17+
同樣地,若確定 user 就代表現在的使用者,我們也可用 `userName` 讓它變得更短。
1818

19-
Modern editors and autocomplete make long variable names easy to write. Don't save on them. A name with 3 words in it is fine.
19+
現代化編輯器的自動完成功能讓寫長命名變數變得很簡單,不要忽略這功能,一個變數名中含有三個單字是適當的。
20+
21+
若你的編輯器沒有自動完成功能,快來選 [一個新的](/code-editors) 吧。
2022

21-
And if your editor does not have proper autocompletion, get [a new one](/code-editors).

1-js/02-first-steps/04-variables/2-declare-variables/task.md

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

33
---
44

5-
# Giving the right name
5+
# 給予正確命名
6+
7+
1. 建立一個變數並以我們星球命名,你會怎樣命名這個變數?
8+
2. 建立一個變數來存放現在網站造訪者的名字,你會怎樣命名這個變數?
69

7-
1. Create a variable with the name of our planet. How would you name such a variable?
8-
2. Create a variable to store the name of a current visitor to a website. How would you name that variable?

1-js/02-first-steps/04-variables/3-uppercast-constant/solution.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
We generally use upper case for constants that are "hard-coded". Or, in other words, when the value is known prior to execution and directly written into the code.
1+
我們通常使用大寫來命名 "寫死的" 常數,或者換句話說,當常數的值在程式執行前就已知並寫在程式碼內時。
22

3-
In this code, `birthday` is exactly like that. So we could use the upper case for it.
3+
這份程式碼中的 `birthday` 是這樣,所以我們可以讓它使用大寫命名。
4+
5+
相對地,`age` 在執行期間才被計算出來。今天我們有一個年齡,一年後就會有另一個。它在整個程式碼被執行的過程中不會改變,但相較於 `birthday` 卻 "沒那麼不變",它是被計算出來的,故我們應該用小寫來命名。
46

5-
In contrast, `age` is evaluated in run-time. Today we have one age, a year after we'll have another one. It is constant in a sense that it does not change through the code execution. But it is a bit "less of a constant" than `birthday`: it is calculated, so we should keep the lower case for it.

1-js/02-first-steps/04-variables/3-uppercast-constant/task.md

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

33
---
44

5-
# Uppercase const?
5+
# 大寫常數?
66

7-
Examine the following code:
7+
檢查底下程式碼:
88

99
```js
1010
const birthday = '18.04.1982';
1111

1212
const age = someCode(birthday);
1313
```
1414

15-
Here we have a constant `birthday` date and the `age` is calculated from `birthday` with the help of some code (it is not provided for shortness, and because details don't matter here).
15+
在這裡我們有個日期常數 `birthday`,和經由 `birthday` 與其他程式碼 (為了保持簡化這邊不提供,因為也不重要) 計算出的 `age` 常數。
1616

17-
Would it be right to use upper case for `birthday`? For `age`? Or even for both?
17+
對於 `birthday` 使用大寫命名是正確的嗎?對於 `age` 呢?或者乾脆兩者都用?
1818

1919
```js
20-
const BIRTHDAY = '18.04.1982'; // make uppercase?
20+
const BIRTHDAY = '18.04.1982'; // 用大寫命名?
2121

22-
const AGE = someCode(BIRTHDAY); // make uppercase?
22+
const AGE = someCode(BIRTHDAY); // 用大寫命名?
2323
```
2424

0 commit comments

Comments
 (0)