Skip to content

Commit c94c2e1

Browse files
linhe0x0leviding
authored andcommitted
1-js/02-first-steps/04-variables (javascript-tutorial#32)
* Transfer the existing translation Co-authored-by: maoxiaoke <thebigyellowbee@qq.com> resolve javascript-tutorial#4 * fix(variables): Adjust some contents * fix(variables): translate more tasks and solutions * 👌 fix: Adjust some words due to code review changes Signed-off-by: sqrtthree <imsqrtthree@gmail.com> * Update task.md * Update article.md * fix: Remove some spaces due to code review changes Signed-off-by: sqrtthree <imsqrtthree@gmail.com>
1 parent 5171127 commit c94c2e1

File tree

7 files changed

+137
-138
lines changed

7 files changed

+137
-138
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")。
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
First, the variable for the name of 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-
Second, 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+
还有,如果我们的确知道用户就是当前的用户的话,我们可以使用更短的 `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+
现代编辑器的自动补全可以让长变量名变得容易书写。不要浪费这个特性。一个名字中包含三个词就挺好的。
2020

21-
And if your editor does not have proper autocompletion, get [a new one](/editors).
21+
如果你的编辑器没有合适的自动补全,换[一个新的吧](/editors)

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

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

33
---
44

5-
# Giving the right name
5+
# 给出正确的名字
66

7-
1. Create the variable with the name of our planet. How would you name such a variable?
8-
2. Create the variable to store the name of the current visitor. How would you name that variable?
7+
1. 使用我们的星球的名字创建一个变量。你会怎么命名这个变量?
8+
2. 创建一个变量来存储当前浏览者的名字。你会怎么命名这个变量?
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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` 确信是这样的。因此我们可以使用大写。
44

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.
5+
在对照组中,`age` 是在运行时计算出的。今天我们有一个年龄,一年以后我们就会有另一个。它在某种意义上不会通过代码的执行而改变。但是相比 `birthday` 它是“少一些常量”的,它是计算出的,因此我们应该使用小写。

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,22 @@ 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
```
24-

0 commit comments

Comments
 (0)