Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1-js/02-first-steps/04-variables #32

Merged
merged 7 commits into from Apr 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,7 +1,7 @@
In the code below, each line corresponds to the item in the task list.
下面的代码,每一行都对应着任务列表中的对应项。

```js run
let admin, name; // can declare two variables at once
let admin, name; // 一次声明两个变量。

name = "John";

Expand Down
10 changes: 5 additions & 5 deletions 1-js/02-first-steps/04-variables/1-hello-variables/task.md
Expand Up @@ -2,9 +2,9 @@ importance: 2

---

# Working with variables
# 使用变量

1. Declare two variables: `admin` and `name`.
2. Assign the value `"John"` to `name`.
3. Copy the value from `name` to `admin`.
4. Show the value of `admin` using `alert` (must output "John").
1. 声明两个变量:`admin` `name`
2. 将值 `"John"` 赋给 `name`
3. `name` 变量中拷贝其值给 `admin`
4. 使用 `alert` 显示 `admin` 的值(一定会输出 "John")。
14 changes: 7 additions & 7 deletions 1-js/02-first-steps/04-variables/2-declare-variables/solution.md
@@ -1,21 +1,21 @@
First, the variable for the name of our planet.
首先,声明变量代表我们星球的名字。

That's simple:
这很简单:

```js
let ourPlanetName = "Earth";
```

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.
注意,我们也可以用一个更短的名字 `planet`,但是它可能并不清楚它指的是什么行星。再啰嗦一点也是挺好的。至少直到这个变量“不太长”就行。

Second, the name of the current visitor:
第二,定义当前浏览者的名字:

```js
let currentUserName = "John";
```

Again, we could shorten that to `userName` if we know for sure that the user is current.
还有,如果我们的确知道用户就是当前的用户的话,我们可以使用更短的 `userName`

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.
现代编辑器的自动补全可以让长变量名变得容易书写。不要浪费这个特性。一个名字中包含三个词就挺好的。

And if your editor does not have proper autocompletion, get [a new one](/editors).
如果你的编辑器没有合适的自动补全,换[一个新的吧](/editors)
6 changes: 3 additions & 3 deletions 1-js/02-first-steps/04-variables/2-declare-variables/task.md
Expand Up @@ -2,7 +2,7 @@ importance: 3

---

# Giving the right name
# 给出正确的名字

1. Create the variable with the name of our planet. How would you name such a variable?
2. Create the variable to store the name of the current visitor. How would you name that variable?
1. 使用我们的星球的名字创建一个变量。你会怎么命名这个变量?
2. 创建一个变量来存储当前浏览者的名字。你会怎么命名这个变量?
@@ -1,5 +1,5 @@
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.
我们通常用大写字母表示“硬编码”的常量。或者,换句话说,当值在执行之前被知道并直接写入代码中的时候。

In this code, `birthday` is exactly like that. So we could use the upper case for it.
在这个代码中 `birthday` 确信是这样的。因此我们可以使用大写。

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.
在对照组中,`age` 是在运行时计算出的。今天我们有一个年龄,一年以后我们就会有另一个。它在某种意义上不会通过代码的执行而改变。但是相比 `birthday` 它是“少一些常量”的,它是计算出的,因此我们应该使用小写。
13 changes: 6 additions & 7 deletions 1-js/02-first-steps/04-variables/3-uppercast-constant/task.md
Expand Up @@ -2,23 +2,22 @@ importance: 4

---

# Uppercase const?
# 大写的常量?

Examine the following code:
检查下面的代码:

```js
const birthday = '18.04.1982';

const age = someCode(birthday);
```

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).
这里我们有一个 `birthday` 日期常量和通过一些有用的代码(为了保持简短这里没有提供,并且细节也无关紧要)从 `birthday` 计算出的 `age` 常量。

Would it be right to use upper case for `birthday`? For `age`? Or even for both?
对于 `birthday` 使用大写方式正确吗?那么 `age` 呢?或者两者?

```js
const BIRTHDAY = '18.04.1982'; // make uppercase?
const BIRTHDAY = '18.04.1982'; // 使用大写?

const AGE = someCode(BIRTHDAY); // make uppercase?
const AGE = someCode(BIRTHDAY); // 使用大写?
```