Skip to content

Commit 52eead9

Browse files
Merge pull request #22 from kooshan75/fucntions
Functions article is translated.
2 parents 3b16df3 + c62b5ab commit 52eead9

File tree

8 files changed

+154
-163
lines changed

8 files changed

+154
-163
lines changed
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
No difference.
1+
فرقی ندارد.

1-js/02-first-steps/14-function-basics/1-if-else-required/task.md

+16-16
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,37 @@ importance: 4
22

33
---
44

5-
# Is "else" required?
5+
# آیا "else" لازم است؟
66

7-
The following function returns `true` if the parameter `age` is greater than `18`.
7+
تابع زیر `true` را برمیگرداند اگر پارامتر `age` از `18` بزرگتر باشد.
88

9-
Otherwise it asks for a confirmation and returns its result:
9+
در غیر اینصورت برای تأیید سوال می‌پرسد و سپس جواب را بر‌میگرداند:
1010

1111
```js
1212
function checkAge(age) {
13-
if (age > 18) {
14-
return true;
13+
if (age > 18) {
14+
return true;
1515
*!*
16-
} else {
17-
// ...
18-
return confirm('Did parents allow you?');
19-
}
16+
} else {
17+
// ...
18+
return confirm('Did parents allow you?');
19+
}
2020
*/!*
2121
}
2222
```
2323

24-
Will the function work differently if `else` is removed?
24+
آیا اگر `else` را حذف کنیم تابع جور دیگری کار می‌کند؟
2525

2626
```js
2727
function checkAge(age) {
28-
if (age > 18) {
29-
return true;
30-
}
28+
if (age > 18) {
29+
return true;
30+
}
3131
*!*
32-
// ...
33-
return confirm('Did parents allow you?');
32+
// ...
33+
return confirm('Did parents allow you?');
3434
*/!*
3535
}
3636
```
3737

38-
Is there any difference in the behavior of these two variants?
38+
آیا هیچ تفاوتی در رفتار این دو حالت وجود دارد؟
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
Using a question mark operator `'?'`:
1+
با استفاده از یک عملگر علامت سوال `'?'`:
22

33
```js
44
function checkAge(age) {
55
return (age > 18) ? true : confirm('Did parents allow you?');
66
}
77
```
88

9-
Using OR `||` (the shortest variant):
9+
با استفاده از OR `||` (کوتاه‌ترین حالت)
1010

1111
```js
1212
function checkAge(age) {
1313
return (age > 18) || confirm('Did parents allow you?');
1414
}
1515
```
1616

17-
Note that the parentheses around `age > 18` are not required here. They exist for better readabilty.
17+
توجه داشته باشید که پرانتزهای دور `age > 18` لازم نیست. برای خوانایی نوشته شده‌ند.

1-js/02-first-steps/14-function-basics/2-rewrite-function-question-or/task.md

+13-13
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@ importance: 4
22

33
---
44

5-
# Rewrite the function using '?' or '||'
5+
# تابع را با کمک '?' یا '||' بازنویسی کنید
66

7-
The following function returns `true` if the parameter `age` is greater than `18`.
7+
تابع زیر `true` را برمیگرداند اگر پارامتر `age` از `18` بزرگتر باشد.
8+
فلان را برمیگرداند
89

9-
Otherwise it asks for a confirmation and returns its result.
10+
در غیر اینصورت برای تأیید سوال می‌پرسد و سپس جواب را بر‌میگرداند:
1011

1112
```js
1213
function checkAge(age) {
13-
if (age > 18) {
14-
return true;
15-
} else {
16-
return confirm('Do you have your parents permission to access this page?');
17-
}
14+
if (age > 18) {
15+
return true;
16+
} else {
17+
return confirm('Do you have your parents permission to access this page?');
18+
}
1819
}
1920
```
2021

21-
Rewrite it, to perform the same, but without `if`, in a single line.
22-
23-
Make two variants of `checkAge`:
22+
بازنویسی کنید، تا همین رفتار، بدون `if`، در یک خط اجرا شود.
2423

25-
1. Using a question mark operator `?`
26-
2. Using OR `||`
24+
دو حالت از `checkAge` بسازید:
25+
۱. با استفاده از عملگر علامت سوال `?`
26+
۲. با استفاده از OR `||`

1-js/02-first-steps/14-function-basics/3-min/solution.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
A solution using `if`:
1+
راه حل با کمک `if`:
22

33
```js
44
function min(a, b) {
@@ -10,12 +10,12 @@ function min(a, b) {
1010
}
1111
```
1212

13-
A solution with a question mark operator `'?'`:
13+
راه حل با علامت سوال `'?'`:
1414

1515
```js
1616
function min(a, b) {
1717
return a < b ? a : b;
1818
}
1919
```
2020

21-
P.S. In the case of an equality `a == b` it does not matter what to return.
21+
پی‌نوشت: در حالت `a == b`، مهم نیست که چه چیزی برگردانده شود.

1-js/02-first-steps/14-function-basics/3-min/task.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ importance: 1
22

33
---
44

5-
# Function min(a, b)
5+
# تابع min(a, b)
66

7-
Write a function `min(a,b)` which returns the least of two numbers `a` and `b`.
7+
تابع `min(a,b)` را بنویسید که کمترین را از دو عدد `a` و `b` خروجی می‌دهد.
88

9-
For instance:
9+
برای نمونه:
1010

1111
```js
1212
min(2, 5) == 2

1-js/02-first-steps/14-function-basics/4-pow/task.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ importance: 4
22

33
---
44

5-
# Function pow(x,n)
5+
# تابع pow(x,n)
66

7-
Write a function `pow(x,n)` that returns `x` in power `n`. Or, in other words, multiplies `x` by itself `n` times and returns the result.
7+
تابع `pow(x,n)` را بنویسید که `x` به توان `n` را برمی‌گرداند.
88

99
```js
1010
pow(3, 2) = 3 * 3 = 9
1111
pow(3, 3) = 3 * 3 * 3 = 27
1212
pow(1, 100) = 1 * 1 * ...* 1 = 1
1313
```
1414

15-
Create a web-page that prompts for `x` and `n`, and then shows the result of `pow(x,n)`.
15+
یک صفحه وب که دو مقدار `x` و `n` را می‌گیرد و جواب `pow(x,n)` را بر‌می‌گرداند را بسازید.
1616

1717
[demo]
1818

19-
P.S. In this task the function should support only natural values of `n`: integers up from `1`.
19+
پی‌نوشت: این سوال فقط اعداد طبیعی را پشتیبانی می‌کند.

0 commit comments

Comments
 (0)