Skip to content

Variables #14

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

Merged
merged 5 commits into from
May 11, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 1-js/01-getting-started/index.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Введення

Про мову JavaScript і робоче середовище, для розробки.
Про мову JavaScript і робоче середовище для розробки.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
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";
name = "Іван";

admin = name;

alert( admin ); // "John"
alert( admin ); // "Іван"
```

10 changes: 5 additions & 5 deletions 1-js/02-first-steps/04-variables/1-hello-variables/task.md
Original file line number Diff line number Diff line change
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. Присвойте значення `"Іван"` змінній `name`.
3. Скопіюйте значення зі змінної `name` в `admin`.
4. Виведіть значення змінної `admin`, використовуючи функцію `alert` (яка повинна показати "Іван").
18 changes: 9 additions & 9 deletions 1-js/02-first-steps/04-variables/2-declare-variables/solution.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
First, the variable for the name of our planet.
1. Змінна для назви нашої планети.

That's simple:
Ось приклад:

```js
let ourPlanetName = "Earth";
let ourPlanetName = "Земля";
```

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:
2. Ім'я поточного відвідувача:

```js
let currentUserName = "John";
let currentUserName = "Іван";
```

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](/code-editors).
Якщо в вашому редакторі немає автодоповнювача, скористайтеся [іншим](/code-editors).
6 changes: 3 additions & 3 deletions 1-js/02-first-steps/04-variables/2-declare-variables/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ importance: 3

---

# Giving the right name
# Придумайте правильні імена

1. Create a variable with the name of our planet. How would you name such a variable?
2. Create a variable to store the name of a current visitor to a website. How would you name that variable?
1. Створіть змінну із назвою нашої планети. Як би ви назвали таку змінну?
2. Створіть змінну для зберігання імені поточного відвідувача сайту. Як би ви назвали таку змінну?
Original file line number Diff line number Diff line change
@@ -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.
Зазвичай, ми використовуємо великі букви для констант, які "жорстко закодовані" (hardcoded). Іншими словами, коли значення константи відоме до початку виконання скрипта і записується безпосередньо в код.

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`, вона обчислюється, тому ми повинні зберегти її в нижньому регістрі.
12 changes: 6 additions & 6 deletions 1-js/02-first-steps/04-variables/3-uppercast-constant/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ 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`, а також `age`, яка вираховується за допомогою функції, використовуючи значення із `birthday` (в даному випадку деталі не мають значення, тому код функції не розглядається).

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); // а тут?
```

Loading