Skip to content

translate part 1, 2.15- functions to AR #36

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 1 commit into from
May 30, 2020
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.
لا اختلاف.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
importance: 4
الأهمية: 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) {
Expand All @@ -21,7 +21,7 @@ function checkAge(age) {
}
```

Will the function work differently if `else` is removed?
هل سيحدث اختلاف إذا حذفنا `else` ?

```js
function checkAge(age) {
Expand All @@ -35,4 +35,4 @@ function checkAge(age) {
}
```

Is there any difference in the behavior of these two variants?
هل هناك أي اختلاف في سلوك الدالتين ؟
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Using a question mark operator `'?'`:
استخدام معامل علامة الاستفهام `'?'`:

```js
function checkAge(age) {
Expand All @@ -14,4 +14,4 @@ function checkAge(age) {
}
```

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
@@ -1,12 +1,12 @@
importance: 4
الأهمية: 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) {
Expand All @@ -18,9 +18,9 @@ function checkAge(age) {
}
```

Rewrite it, to perform the same, but without `if`, in a single line.
اعد كتابتها للحصول على نفس النتيجة ولكن بدون `if` وفي سطر واحد.

Make two variants of `checkAge`:
اعد كتابة `checkAge`:

1. Using a question mark operator `?`
2. Using OR `||`
1. باستخدام معامل علامة الاستفهام `?`
2. باستخدام OR `||`
6 changes: 3 additions & 3 deletions 1-js/02-first-steps/15-function-basics/3-min/solution.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
A solution using `if`:
الحل باستخدام `if`:

```js
function min(a, b) {
Expand All @@ -10,12 +10,12 @@ function min(a, b) {
}
```

A solution with a question mark operator `'?'`:
الحل باستخدام معامل علامة الاستفهام `'?'`:

```js
function min(a, b) {
return a < b ? a : b;
}
```

P.S. In the case of an equality `a == b` it does not matter what to return.
لاحظ أن في حالة إذا كان `a == b` لا يهم أي قيمة نرجع.
8 changes: 4 additions & 4 deletions 1-js/02-first-steps/15-function-basics/3-min/task.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
importance: 1
الأهمية: 1

---

# Function min(a, b)
# دالة min(a, b)

Write a function `min(a,b)` which returns the least of two numbers `a` and `b`.
اكتب دالة `min(a,b)` التي ترجع الرقم الأقل بين رقمين `a` و `b`.

For instance:
مثلًا:

```js
min(2, 5) == 2
Expand Down
10 changes: 5 additions & 5 deletions 1-js/02-first-steps/15-function-basics/4-pow/task.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
importance: 4
الأهمية: 4

---

# Function pow(x,n)
# دالة pow(x,n)

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.
اكتب دالة `pow(x,n)` التي ترجع `x` مرفوعة لأس `n`. أو بكلمات أخرى, تضرب `x` في نفسها عدد `n` من المرات وترجع الناتج.

```js
pow(3, 2) = 3 * 3 = 9
pow(3, 3) = 3 * 3 * 3 = 27
pow(1, 100) = 1 * 1 * ...* 1 = 1
```

Create a web-page that prompts for `x` and `n`, and then shows the result of `pow(x,n)`.
انشئ صفحة ويب تطلب من المستخدم قيم `x` و `n` ثم اعرض نتيجة `pow(x,n)`.

[demo]

P.S. In this task the function should support only natural values of `n`: integers up from `1`.
لاحظ أن في هذا السؤال يجب أن تدعم الدالة الأرقام الطبيعية فقط ل `n`: أرقام موجبة أكبر من `1`.
Loading