File tree Expand file tree Collapse file tree 2 files changed +16
-16
lines changed
1-js/02-first-steps/14-function-basics/2-rewrite-function-question-or Expand file tree Collapse file tree 2 files changed +16
-16
lines changed Original file line number Diff line number Diff line change 1
- Using a question mark operator ` '?' ` :
1
+ با استفاده از یک عملگر علامت سوال ` '?' ` :
2
2
3
3
``` js
4
4
function checkAge (age ) {
5
5
return (age > 18 ) ? true : confirm (' Did parents allow you?' );
6
6
}
7
7
```
8
8
9
- Using OR ` || ` (the shortest variant):
9
+ با استفاده از OR ` || ` (کوتاهترین حالت)
10
10
11
11
``` js
12
12
function checkAge (age ) {
13
13
return (age > 18 ) || confirm (' Did parents allow you?' );
14
14
}
15
15
```
16
16
17
- Note that the parentheses around ` age > 18 ` are not required here. They exist for better readabilty .
17
+ توجه داشته باشید که پرانتزهای دور ` age > 18 ` لازم نیست. برای خوانایی نوشته شدهند .
Original file line number Diff line number Diff line change @@ -2,25 +2,25 @@ importance: 4
2
2
3
3
---
4
4
5
- # Rewrite the function using '?' or '||'
5
+ # تابع را با کمک '?' یا '||' بازنویسی کنید
6
6
7
- The following function returns ` true ` if the parameter ` age ` is greater than ` 18 ` .
7
+ تابع زیر ` true ` را برمیگرداند اگر پارامتر ` age ` از ` 18 ` بزرگتر باشد.
8
+ فلان را برمیگرداند
8
9
9
- Otherwise it asks for a confirmation and returns its result.
10
+ در غیر اینصورت برای تأیید سوال میپرسد و سپس جواب را برمیگرداند:
10
11
11
12
``` js
12
13
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
+ }
18
19
}
19
20
```
20
21
21
- Rewrite it, to perform the same, but without ` if ` , in a single line.
22
-
23
- Make two variants of ` checkAge ` :
22
+ بازنویسی کنید، تا همین رفتار، بدون ` if ` ، در یک خط اجرا شود.
24
23
25
- 1 . Using a question mark operator ` ? `
26
- 2 . Using OR ` || `
24
+ دو حالت از ` checkAge ` بسازید:
25
+ ۱. با استفاده از عملگر علامت سوال ` ? `
26
+ ۲. با استفاده از OR ` || `
You can’t perform that action at this time.
0 commit comments