Skip to content
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 +1 @@
No difference.
فرقی ندارد.
32 changes: 16 additions & 16 deletions 1-js/02-first-steps/14-function-basics/1-if-else-required/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,37 @@ importance: 4

---

# Is "else" required?
# آیا "else" لازم است؟

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

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

```js
function checkAge(age) {
if (age > 18) {
return true;
if (age > 18) {
return true;
*!*
} else {
// ...
return confirm('Did parents allow you?');
}
} else {
// ...
return confirm('Did parents allow you?');
}
*/!*
}
```

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

```js
function checkAge(age) {
if (age > 18) {
return true;
}
if (age > 18) {
return true;
}
*!*
// ...
return confirm('Did parents allow you?');
// ...
return confirm('Did parents allow you?');
*/!*
}
```

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

```js
function checkAge(age) {
return (age > 18) ? true : confirm('Did parents allow you?');
}
```

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

```js
function checkAge(age) {
return (age > 18) || confirm('Did parents allow you?');
}
```

Note that the parentheses around `age > 18` are not required here. They exist for better readabilty.
توجه داشته باشید که پرانتزهای دور `age > 18` لازم نیست. برای خوانایی نوشته شده‌ند.
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@ importance: 4

---

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

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

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

```js
function checkAge(age) {
if (age > 18) {
return true;
} else {