Skip to content

Variables #79

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 3 commits into from
Jul 27, 2021
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
Original file line number Diff line number Diff line change
@@ -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
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`-ին վերագրեք `"John"` արժեքը:
3. Պատճենեք `name`-ի արժեքը `admin`-ի մեջ:
4. Ցույց տվեք `admin`-ի արժեքը `alert`-ի միջոցով (պետք է արտատպի "John"):
14 changes: 7 additions & 7 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 @@
## The variable for our planet
## Մեր մոլորակի անունը պարունակող փոփոխականը

That's simple:
Այստեղ ամեն ինչ պարզ է՝

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

Note, we could use a shorter name `planet`, but it might not be obvious what planet it refers to. It's nice to be more verbose. At least until the variable isNotTooLong.
Կարող էինք նաև օգտագործել ավելի կարճ `planet` անունը, բայց հասկանալի չէր լինի, թե որ մոլորակի անունն է այն: Ավելի լավ է փոփոխականի անունը լինի երկար, բայց հասկանալի: Բայց ոչ շատ երկար:

## 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](/code-editors).
Եվ եթե Ձեզ խմբագրիչը չունի կոդի ինքնաշխատ հուշումներ (autocompletion) տրամադրելու հնարավորությունը, խորհուրդ ենք տալիս [փոխել այն](/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.
Ընդհանուր առմամբ մեծատառերով գրվում են այսպես կոչված «hard-coded» հաստատունները: Այլ կերպ ասած, երբ հաստատունի արժեքը նախօրոք հայտնի է մինչև կոդը գործարկելը, և այդ արժեքը ուղղակի գրված է կոդում:

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); // թե՞ age-ը
```

Loading