Skip to content

Commit a408f10

Browse files
authored
Merge pull request #100 from mahdiHashemi14/master
Logical operators
2 parents bef7f4e + a1c1d34 commit a408f10

File tree

18 files changed

+149
-150
lines changed

18 files changed

+149
-150
lines changed

1-js/02-first-steps/11-logical-operators/1-alert-null-2-undefined/solution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
The answer is `2`, that's the first truthy value.
1+
جواب `2` است، آن اولین مقدار truthy است.
22

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

1-js/02-first-steps/11-logical-operators/1-alert-null-2-undefined/task.md

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

33
---
44

5-
# What's the result of OR?
5+
# نتیجه OR چیست؟
66

7-
What is the code below going to output?
7+
کد پایین چه چیزی را خروجی خواهد داد؟
88

99
```js
1010
alert( null || 2 || undefined );
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
The answer: first `1`, then `2`.
1+
جواب: اول `1`، سپس `2`.
22

33
```js run
44
alert( alert(1) || 2 || alert(3) );
55
```
66

7-
The call to `alert` does not return a value. Or, in other words, it returns `undefined`.
7+
صدا زدن `alert` مقداری بر نمی گرداند. یا، به عبارتی دیگر، `undefined` را بر می گرداند.
88

9-
1. The first OR `||` evaluates its left operand `alert(1)`. That shows the first message with `1`.
10-
2. The `alert` returns `undefined`, so OR goes on to the second operand searching for a truthy value.
11-
3. The second operand `2` is truthy, so the execution is halted, `2` is returned and then shown by the outer alert.
9+
1. اولین OR `||` عملوند سمت چپ خود `alert(1)` را ارزیابی میکند. آن اولین پیام که `1` است را نمایش می دهد.
10+
2. `alert` مقدار `undefined` را بر می گرداند، پس OR به سمت عملوند دوم برای پیدا کردن یک مقدار truthy ادامه می دهد.
11+
3. عملوند دوم `2` turthy است، پس عملیات متوقف شده، `2` بر گردانده می شود و سپس توسط alert بیرونی نمایش داده می شود.
1212

13-
There will be no `3`, because the evaluation does not reach `alert(3)`.
13+
هیچ `3`ای در کار نخواهد بود، چون ارزیابی به `alert(3)` نمی رسد.

1-js/02-first-steps/11-logical-operators/2-alert-or/task.md

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

33
---
44

5-
# What's the result of OR'ed alerts?
5+
# نتیجه alert های دارای OR چیست؟
66

7-
What will the code below output?
7+
کد پایین چه چیزی را خروجی خواهد داد؟
88

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

1-js/02-first-steps/11-logical-operators/3-alert-1-null-2/solution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
The answer: `null`, because it's the first falsy value from the list.
1+
جواب: `null`، چون اولین مقدار falsy از لیست است.
22

33
```js run
44
alert( 1 && null && 2 );

1-js/02-first-steps/11-logical-operators/3-alert-1-null-2/task.md

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

33
---
44

5-
# What is the result of AND?
5+
# نتیجه AND جیست؟
66

7-
What is this code going to show?
7+
این کد چه چیزی را نمایش خواهد داد؟
88

99
```js
1010
alert( 1 && null && 2 );
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
The answer: `1`, and then `undefined`.
1+
جواب: `1`، و سپس `undefined`.
22

33
```js run
44
alert( alert(1) && alert(2) );
55
```
66

7-
The call to `alert` returns `undefined` (it just shows a message, so there's no meaningful return).
7+
صدا زدن `alert` `undefined` را بر می گرداند (آن فقط یک پیام را نمایش می دهد، پس هیچ return معناداری وجود ندارد).
88

9-
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.
9+
به خاطر آن، `&&` عملوند چپ را ارزیابی میکند (`1` را نمایش می دهد)، و بلافاصله متوقف می شود، چون `undefined` یک مقدار falsy است. و `&&` به دنبال یک مقدار falsy می گردد و آن را بر می گرداند، بنابراین کار تمام می شود.
1010

1-js/02-first-steps/11-logical-operators/4-alert-and/task.md

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

33
---
44

5-
# What is the result of AND'ed alerts?
5+
# نتیجه alert های دارای AND چیست؟
66

7-
What will this code show?
7+
این کد چه چیزی را نمایش خواهد داد؟
88

99
```js
1010
alert( alert(1) && alert(2) );
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
The answer: `3`.
1+
جواب: `3`.
22

33
```js run
44
alert( null || 2 && 3 || 4 );
55
```
66

7-
The precedence of AND `&&` is higher than `||`, so it executes first.
7+
اولویت AND `&&` از `||` بیشتر است، ینابراین اول اجرا می شود.
88

9-
The result of `2 && 3 = 3`, so the expression becomes:
9+
نتیجه `3 = 3 && 2`، پس عبارت تبدیل می شود به:
1010

1111
```
1212
null || 3 || 4
1313
```
1414

15-
Now the result is the first truthy value: `3`.
15+
حالا نتیجه اولین مقدار truthy است: `3`.
1616

1-js/02-first-steps/11-logical-operators/5-alert-and-or/task.md

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

33
---
44

5-
# The result of OR AND OR
5+
# نتیجه OR AND OR
66

7-
What will the result be?
7+
نتیجه چه خواهد بود؟
88

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

1-js/02-first-steps/11-logical-operators/6-check-if-in-range/task.md

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

33
---
44

5-
# Check the range between
5+
# حدود بین را بررسی کنید
66

7-
Write an `if` condition to check that `age` is between `14` and `90` inclusively.
7+
یک شرط `if` بنویسید که بررسی کند `age` بین `14` و `90` به صورتی که شامل خودشان هم بشود هست یا نه.
88

9-
"Inclusively" means that `age` can reach the edges `14` or `90`.
9+
"شامل خودشان" یعنی `age` می تواند به مرز `14` و `90` هم برسد.

1-js/02-first-steps/11-logical-operators/7-check-if-out-range/solution.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
The first variant:
1+
نوع اول:
22

33
```js
44
if (!(age >= 14 && age <= 90))
55
```
66

7-
The second variant:
7+
نوع دوم:
88

99
```js
1010
if (age < 14 || age > 90)

1-js/02-first-steps/11-logical-operators/7-check-if-out-range/task.md

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

33
---
44

5-
# Check the range outside
5+
# محدوده خارج را بررسی کنید
66

7-
Write an `if` condition to check that `age` is NOT between `14` and `90` inclusively.
7+
یک شرط `if` بنویسید که بررسی کند `age` بین `14` و `90` به صورتی که که شامل خود آنها هم بشود نباشد.
88

9-
Create two variants: the first one using NOT `!`, the second one -- without it.
9+
دو نوع بسازید: اولی با استفاده از NOT `!`، و دومی بدون آن.

1-js/02-first-steps/11-logical-operators/8-if-question/solution.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
The answer: the first and the third will execute.
1+
جواب: اولی و سومی اجرا خواهند شد.
22

3-
Details:
3+
جزییات:
44

55
```js run
6-
// Runs.
7-
// The result of -1 || 0 = -1, truthy
6+
// اجرا می شود.
7+
// نتیجه 1- = 0 || 1-، truthy
88
if (-1 || 0) alert( 'first' );
99

10-
// Doesn't run
10+
// اجرا نمی شود.
1111
// -1 && 0 = 0, falsy
1212
if (-1 && 0) alert( 'second' );
1313

14-
// Executes
15-
// Operator && has a higher precedence than ||
16-
// so -1 && 1 executes first, giving us the chain:
14+
// اجرا می شود
15+
// عملوند && اولویت بیشتری نسبت به || دارد
16+
// پس 1 && 1- اول اجرا می شود، و به ما زنجیره را می دهد:
1717
// null || -1 && 1 -> null || 1 -> 1
1818
if (null || -1 && 1) alert( 'third' );
1919
```

1-js/02-first-steps/11-logical-operators/8-if-question/task.md

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

33
---
44

5-
# A question about "if"
5+
# یک سوال درباره "if"
66

7-
Which of these `alert`s are going to execute?
7+
کدام یک از `alert`ها اجرا خواهد شد؟
88

9-
What will the results of the expressions be inside `if(...)`?
9+
نتیجه عبارت های داخل `if(...)` چه خواهد بود؟
1010

1111
```js
1212
if (-1 || 0) alert( 'first' );

1-js/02-first-steps/11-logical-operators/9-check-login/solution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ if (userName === 'Admin') {
2222
}
2323
```
2424

25-
Note the vertical indents inside the `if` blocks. They are technically not required, but make the code more readable.
25+
به تورفتگی عمودی درون بلوک های `if` توجه کنید. از لحاظ فنی به آنها نیازی نیست، اما کد را خواناتر می کنند.

1-js/02-first-steps/11-logical-operators/9-check-login/task.md

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

33
---
44

5-
# Check the login
5+
# login را بررسی کنید
66

7-
Write the code which asks for a login with `prompt`.
7+
کدی بنویسید که با `prompt` برای login درخواست کند.
88

9-
If the visitor enters `"Admin"`, then `prompt` for a password, if the input is an empty line or `key:Esc` -- show "Canceled", if it's another string -- then show "I don't know you".
9+
اگر بازدید کننده `"Admin"` وارد کند، سپس برای رمز عبور `prompt` کنید، اگر ورودی یک خط خالی یا `key:Esc` باشد -- "Canceled" را نمایش دهید، اگر رشته(string) دیگری باشد -- سپس "I don't know you" را نشان دهید.
1010

11-
The password is checked as follows:
11+
رمز عبور به شکل زیر بررسی می شود:
1212

13-
- If it equals "TheMaster", then show "Welcome!",
14-
- Another string -- show "Wrong password",
15-
- For an empty string or cancelled input, show "Canceled"
13+
- اگر برابر با "TheMaster" باشد، سپس "Welcome!" را نمایش دهید،
14+
- اگر رشته(string) دیگری باشد -- "Wrong password" را نمایش دهید،
15+
- اگر یک رشته(string) خالی یا ورودی cancelled باشد، "Canceled" را نمایش دهید
1616

17-
The schema:
17+
طرح:
1818

1919
![](ifelse_task.svg)
2020

21-
Please use nested `if` blocks. Mind the overall readability of the code.
21+
لطفا از بلوک های `if` تو در تو استفاده کنید. خوانایی کلی کد را در نظر بگیرید.
2222

23-
Hint: passing an empty input to a prompt returns an empty string `''`. Pressing `key:ESC` during a prompt returns `null`.
23+
راهنمایی جزیی: رد کردن یک ورودی خالی به prompt یک رشته خالی `''` بر می گرداند. فشار دادن `key:ESC` در حین prompt `null` را بر می گرداند.
2424

25-
[demo]
25+
[دمو]

0 commit comments

Comments
 (0)