Skip to content

Logical operators #82

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 27 commits into from
Aug 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
eb51f73
article.md to line 19
vahmelk99 Aug 2, 2021
27c1964
OR operator ended
vahmelk99 Aug 3, 2021
7a0456e
&& translated
vahmelk99 Aug 4, 2021
e57228d
article added
vahmelk99 Aug 5, 2021
ac13025
importance translated
vahmelk99 Aug 5, 2021
6612518
1-alert-null-2-undefined translated
vahmelk99 Aug 5, 2021
b662a96
3-alert-1-null-2 translated
vahmelk99 Aug 5, 2021
c0cdc9a
2-alert-or translated
vahmelk99 Aug 6, 2021
7646dd5
2-alert-or translated
vahmelk99 Aug 6, 2021
f0d57a5
4-alert-and translated
vahmelk99 Aug 6, 2021
54448c2
5-alert-and-or translated
vahmelk99 Aug 6, 2021
5895fdc
titles rename and 6th ex.
vahmelk99 Aug 6, 2021
7b2e8c7
7-check-if-out-range translated
vahmelk99 Aug 6, 2021
ccc824f
8-if-question translated
vahmelk99 Aug 6, 2021
1bb3af5
start translating 9-check-login
vahmelk99 Aug 6, 2021
addba0d
Merge branch 'master' of https://github.com/vahmelk99/hy.javascript.info
vahmelk99 Aug 6, 2021
61801fd
9-check-login translated
vahmelk99 Aug 6, 2021
fe68296
translation bugfixes in logical operators
vahmelk99 Aug 11, 2021
1f1ea7d
Update 1-js/02-first-steps/11-logical-operators/3-alert-1-null-2/solu…
vahmelk99 Aug 13, 2021
87442eb
Update 1-js/02-first-steps/11-logical-operators/4-alert-and/task.md
vahmelk99 Aug 13, 2021
8b25f3b
Update 1-js/02-first-steps/11-logical-operators/article.md
vahmelk99 Aug 13, 2021
dab4805
Update 1-js/02-first-steps/11-logical-operators/article.md
vahmelk99 Aug 13, 2021
34f3333
Update 1-js/02-first-steps/11-logical-operators/article.md
vahmelk99 Aug 13, 2021
dde7793
Update 1-js/02-first-steps/11-logical-operators/article.md
vahmelk99 Aug 13, 2021
a12a35c
Update 1-js/02-first-steps/11-logical-operators/article.md
vahmelk99 Aug 13, 2021
d85ba1b
Update 1-js/02-first-steps/11-logical-operators/article.md
vahmelk99 Aug 13, 2021
a99cafd
article fixed
vahmelk99 Aug 13, 2021
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,6 +1,5 @@
The answer is `2`, that's the first truthy value.
Պատասխանը `2` է, քանի որ այն առաջին ճշմարիտ արժեքն է։

```js run
alert( null || 2 || undefined );
```

Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ importance: 5

---

# What's the result of OR?
# Ի՞նչ է հետևյալ ԿԱՄ-ով արտահայտության արդյունքը

What is the code below going to output?
Ի՞նչ կտպի ներքևում գրված ծրագիրը։

```js
alert( null || 2 || undefined );
```

12 changes: 6 additions & 6 deletions 1-js/02-first-steps/11-logical-operators/2-alert-or/solution.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
The answer: first `1`, then `2`.
Այն կտպի `1`, այնուհետև `2`։

```js run
alert( alert(1) || 2 || alert(3) );
```

The call to `alert` does not return a value. Or, in other words, it returns `undefined`.
`alert`֊ի կանչը չի վերադարձնում ոչ մի արժեք։ Կամ այլ կերպ ասած վերադարձնում է `undefined`։

1. The first OR `||` evaluates its left operand `alert(1)`. That shows the first message with `1`.
2. The `alert` returns `undefined`, so OR goes on to the second operand searching for a truthy value.
3. The second operand `2` is truthy, so the execution is halted, `2` is returned and then shown by the outer alert.
1. Սկզբում ԿԱՄ `||`֊ը հաշվում (evaluates) է իր ձախ կողմի օպերանդը՝ `alert(1)`, որն էլ էկրանին ցույց է տալիս `1` արժեքը։
2. `alert`֊ը վերադարձնում է `undefined`։ ԿԱՄ֊ը անցնում է երկրորդ օպերանդին՝ որոնելով ճշմարիտ արժեք։
3. Երկրորդ օպերանդը `2` է, որը ճշմարիտ է, և ԿԱՄ֊ը դադարեցնում է իր հաշվարկները։ `2`֊ը վերադարձվում է և ցուցադրվում էկրանին դրսի `alert`֊ի միջոցով։

There will be no `3`, because the evaluation does not reach `alert(3)`.
`3`֊ը չի երևա էկրանին, քանի որ ԿԱՄ֊ը կանգ է առնում երկրորդ օպերանդի վրա և չի հասնում `alert(3)`֊ին։
5 changes: 2 additions & 3 deletions 1-js/02-first-steps/11-logical-operators/2-alert-or/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ importance: 3

---

# What's the result of OR'ed alerts?
# Ի՞նչ է հետևյալ ԿԱՄ-ով արտահայտության արդյունքը

What will the code below output?
Ի՞նչ կտպի ներքևում գրված ծրագիրը։

```js
alert( alert(1) || 2 || alert(3) );
```

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
The answer: `null`, because it's the first falsy value from the list.
Պատասխանը `null` է, քանի որ այն առաջին սխալական արժեքն է։

```js run
alert( 1 && null && 2 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ importance: 5

---

# What is the result of AND?
# Ի՞նչ է հետևյալ ԵՎ-ով արտահայտության արդյունքը:

What is this code going to show?
Ի՞նչ կտպի ներքևում գրված ծրագիրը։

```js
alert( 1 && null && 2 );
```

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
The answer: `1`, and then `undefined`.
Այն կտպի `1`, այնուհետև `undefined`։

```js run
alert( alert(1) && alert(2) );
```

The call to `alert` returns `undefined` (it just shows a message, so there's no meaningful return).
`alert`֊ի կանչը տպում է էկրանին և վերադարձնում `undefined`։

Because of that, `&&` evaluates the left operand (outputs `1`), and immediately stops, because `undefined` is a falsy value. And `&&` looks for a falsy value and returns it, so it's done.
Այդ պատճառով, երբ `&&`֊ը ավարտում է ձախ օպերանդի հաշվարկը (էկրանին ցուցադրում է `1`), անմիջապես կանգ է առնում, քանի որ `undefined`֊ը սխալական արժեք է։ `&&`֊ը փնտրում է առաջին սխալական արժեքը և վերադարձնում այն։

5 changes: 2 additions & 3 deletions 1-js/02-first-steps/11-logical-operators/4-alert-and/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ importance: 3

---

# What is the result of AND'ed alerts?
# Ի՞նչ է հետևյալ ԵՎ-ով արտահայտության արդյունքը

What will this code show?
Ի՞նչ կտպի ներքևում գրված ծրագիրը։

```js
alert( alert(1) && alert(2) );
```

Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
The answer: `3`.
Պատասխանը `3` է։

```js run
alert( null || 2 && 3 || 4 );
```

The precedence of AND `&&` is higher than `||`, so it executes first.
ԵՎ `&&`֊ի նախապատվությունը ավելի բարձր է քան `||`֊ինը, հետևաբար այն ավելի շուտ կկատարվի։

The result of `2 && 3 = 3`, so the expression becomes:
Քանի որ `2 && 3 = 3`, ապա կստանանք հետևյալ արտահայտությունը․

```
null || 3 || 4
```

Now the result is the first truthy value: `3`.
Եվ կստանանք պատասխանը առաջին ճշմարիտ արժեքը՝ `3`։

Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ importance: 5

---

# The result of OR AND OR
# Ի՞նչ է հետևյալ ԵՎ-ով և ԿԱՄ֊ով արտահայտության արդյունքը

What will the result be?
Ի՞նչ կտպի ներքևում գրված ծրագիրը։

```js
alert( null || 2 && 3 || 4 );
```

Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ importance: 3

---

# Check the range between
# Միջակայքի ստուգում

Write an `if` condition to check that `age` is between `14` and `90` inclusively.
Գրեք `if` պայման, որը կստուգի արդյոք `age` փոփոխականը ընկած է `14` և `90` թվերի միջակայքում, այդ թվերը ներառյալ։

"Inclusively" means that `age` can reach the edges `14` or `90`.
"Ներառյալ" նշանակում է, որ `age`֊ը կարող է ընդունել `14` կամ `90` արժեքները նույնպես։
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
The first variant:
Առաջին եղանակը․

```js
if (!(age >= 14 && age <= 90))
```

The second variant:
Երկրորդ եղանակը․

```js
if (age < 14 || age > 90)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ importance: 3

---

# Check the range outside
# Միջակայքից դուրս ստուգում

Write an `if` condition to check that `age` is NOT between `14` and `90` inclusively.
Գրեք `if` պայման, որը կստուգի արդյոք `age` փոփոխականը ընկած ՉԷ `14` և `90` թվերի միջակայքում, այդ թվերը ներառյալ։

Create two variants: the first one using NOT `!`, the second one -- without it.
Խնդրիը լուծեք երկու եղանակով․ առաջինը օգտագործելով ՈՉ `!` օպերատորը, երկրորդը առանց ՈՉ֊ի։
24 changes: 12 additions & 12 deletions 1-js/02-first-steps/11-logical-operators/8-if-question/solution.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
The answer: the first and the third will execute.
Պատասխան՝ առաջին և երրորդ `alert`֊ները կկանչվեն։

Details:
Մանրամասներ․

```js run
// Runs.
// The result of -1 || 0 = -1, truthy
if (-1 || 0) alert( 'first' );
// Կանչվում է,
// քանի որ -1 || 0 = -1 ճշմարիտ է
if (-1 || 0) alert('առաջին')

// Doesn't run
// -1 && 0 = 0, falsy
if (-1 && 0) alert( 'second' );
// Չի կանչվում,
// քանի որ -1 && 0 = 0 սխալական է
if (-1 && 0) alert('երկրորդ')

// Executes
// Operator && has a higher precedence than ||
// so -1 && 1 executes first, giving us the chain:
// Կնչվում է, քանի որ
// && օպերատորի նախապատվությունը ավելի բարձր է, քան ||֊ինը,
// այսպիսով -1 && 1 հաշվվում է առաջինը։ Ստանում ենք հետևյալ շղթան․
// null || -1 && 1 -> null || 1 -> 1
if (null || -1 && 1) alert( 'third' );
if (null || -1 && 1) alert('երրորդ')
```

13 changes: 6 additions & 7 deletions 1-js/02-first-steps/11-logical-operators/8-if-question/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ importance: 5

---

# A question about "if"
# Հարց "if"֊ի մասին

Which of these `alert`s are going to execute?
Այս `alert`֊ներից որո՞նք կաշխատեն։

What will the results of the expressions be inside `if(...)`?
Ի՞նչ կլինի `if(...)`֊երի ներսում գրված արտահայտությունների արժեքները։

```js
if (-1 || 0) alert( 'first' );
if (-1 && 0) alert( 'second' );
if (null || -1 && 1) alert( 'third' );
if (-1 || 0) alert('առաջին')
if (-1 && 0) alert('երկրորդ')
if (null || -1 && 1) alert('երրորդ')
```

Loading