Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
665e392
Fix typos
mahdiHash Mar 28, 2021
8e5707f
Translate solution.md of " 2-which-value-while"
mahdiHash Mar 28, 2021
c998f25
Translate task.md of "3-which-value-for"
mahdiHash Mar 28, 2021
fc9698a
Translate task.md of "3-which-value-for"
mahdiHash Mar 28, 2021
8eb82e7
Translate solution.md of "3-which-value-for"
mahdiHash Mar 28, 2021
b61cbbe
Translate task.md of "4-for-even"
mahdiHash Mar 28, 2021
7930ad0
Translate solution.md of "4-for-even"
mahdiHash Mar 28, 2021
77fc525
Translate task.md of "5-replace-for-while"
mahdiHash Mar 28, 2021
2a417e3
Translate solution.md of "5-replace-for-while"
mahdiHash Mar 28, 2021
979c031
Translate task.md of "6-repeat-until-correct"
mahdiHash Mar 28, 2021
5794364
Translate solution.md of "6-repeat-until-correct"
mahdiHash Mar 28, 2021
478e29c
Translate task.md (read description)
mahdiHash Mar 28, 2021
2d7c860
Translate first part of article.md
mahdiHash Mar 29, 2021
4b3fcf6
Merge pull request #1 from javascript-tutorial/master
mahdiHash Mar 29, 2021
d702bed
Change a word
mahdiHash Mar 29, 2021
a4dca95
Translate second part of article.md
mahdiHash Mar 29, 2021
fafbb9a
Translate third part of article.md
mahdiHash Mar 29, 2021
d091837
Translate forth part of article.md
mahdiHash Mar 29, 2021
0261a80
Translate 5th part of article.md
mahdiHash Mar 30, 2021
b0d6e90
Translate 6th part of article.md
mahdiHash Mar 30, 2021
ed966a3
Translate article.md
mahdiHash Mar 30, 2021
bef5760
Change a word
mahdiHash Mar 30, 2021
70c8c9e
Change two words
mahdiHash Mar 30, 2021
d421e8e
Fix mentioned problems and change some lines
mahdiHash Mar 30, 2021
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
Expand Up @@ -8,7 +8,7 @@ while (i) {
}
```

در هر بار تکرار حلقه متغیر `i` به مقدار `1` عدد کم میشود. عبارت `while(i)` وقتی به `i = 0` برسد متوقف میشود.
در هر بار تکرار حلقه متغیر `i` به مقدار `1` عدد کم می شود. عبارت `while(i)` وقتی به `i = 0` برسد متوقف می شود.

حالا گام های حلقه به این صورت است ("تشریح حلقه"):

Expand Down
2 changes: 1 addition & 1 deletion 1-js/02-first-steps/13-while-for/1-loop-last-value/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ importance: 3

# آخرین مقدار حلقه

آخرین مقداری که نمایش داده میشود چیست؟ چرا؟
آخرین مقداری که نمایش داده می شود چیست؟ چرا؟

```js
let i = 3;
Expand Down
24 changes: 12 additions & 12 deletions 1-js/02-first-steps/13-while-for/2-which-value-while/solution.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
The task demonstrates how postfix/prefix forms can lead to different results when used in comparisons.
تمرین نشان می دهد که چگونه شکل های پسوند/پیشوند می توانند باعث نتایج متفاوت بشوند وقتی که در مقایسه ها استفاده می شوند.

1. **From 1 to 4**
1. **از 1 تا 4**

```js run
let i = 0;
while (++i < 5) alert( i );
```

The first value is `i = 1`, because `++i` first increments `i` and then returns the new value. So the first comparison is `1 < 5` and the `alert` shows `1`.
مقدار اول `i = 1` است، چون `++i` اول `i` را افزایش می دهد و سپس مقدار جدید را بر می گرداند. پس مقایسه اول `5 < 1` است و `alert` مقدار `1` را نمایش می دهد.

Then follow `2, 3, 4…` -- the values show up one after another. The comparison always uses the incremented value, because `++` is before the variable.
سپس `...4 ،3 ،2` -- مقدارها یکی پس از دیگری نمایان می شوند. مقایسه همیشه از مقدار افزایش یافته استفاده می کند، چون `++` قبل از متغیر است.

Finally, `i = 4` is incremented to `5`, the comparison `while(5 < 5)` fails, and the loop stops. So `5` is not shown.
2. **From 1 to 5**
در نهایت، `i = 4` است که به `5` افزایش پیدا می کند، مقایسه `while(5 < 5)` شکست می خورد، و حلقه متوقف می شود. بنابراین `5` نمایش داده نمی شود.
2. **از 1 تا 5**

```js run
let i = 0;
while (i++ < 5) alert( i );
```

The first value is again `i = 1`. The postfix form of `i++` increments `i` and then returns the *old* value, so the comparison `i++ < 5` will use `i = 0` (contrary to `++i < 5`).
اولین مقدار باز هم `i = 1` است. شکل پسوند `i++` `i` را افزایش می دهد و سپس مقدار *قدیمی* را بر می گرداند، بنابراین مقایسه `i++ < 5` از `i = 0` استفاده خواهد کرد (متضاد `++i < 5`)

But the `alert` call is separate. It's another statement which executes after the increment and the comparison. So it gets the current `i = 1`.
اما صدا زدن `alert` جداگانه است. آن یک دستور دیگر است که بعد از افزایش و مقایسه اجرا می شود. پس `i = 1` را دریافت می کند.

Then follow `2, 3, 4…`
سپس `...4 ،3 ،2`

بیایید روی `i = 4` متوقف شویم. شکل پیشوند `++i` آن را افزایش می دهد و از `5` در مقایسه استفاده می کند. اما اینجا ما شکل پسوند `i++` را داریم. پس `i` را به `5` افزایش می دهد، اما مقدار قدیمی را بر می گرداند. به این دلیل مقایسه در واقع `while(4 < 5)` است -- درست است، و کنترل به دست `alert` می افتد.

Let's stop on `i = 4`. The prefix form `++i` would increment it and use `5` in the comparison. But here we have the postfix form `i++`. So it increments `i` to `5`, but returns the old value. Hence the comparison is actually `while(4 < 5)` -- true, and the control goes on to `alert`.

The value `i = 5` is the last one, because on the next step `while(5 < 5)` is false.
مقدار `i = 5` آخرین مقدار است، زیرا در مرحله بعد `while(5 < 5)` اشتباه می شود.
4 changes: 2 additions & 2 deletions 1-js/02-first-steps/13-while-for/2-which-value-while/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ importance: 4

هر دو حلقه، مقادیر یکسانی را `alert` میکنند یا خیر؟

1. حالت پیشوند `i++`:
1. حالت پیشوند `++i`:

```js
let i = 0;
while (++i < 5) alert( i );
```

2. حالت پسوند `++i`:
2. حالت پسوند `i++`:

```js
let i = 0;
Expand Down
14 changes: 7 additions & 7 deletions 1-js/02-first-steps/13-while-for/3-which-value-for/solution.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
**The answer: from `0` to `4` in both cases.**
**جواب: از 0 تا 4 در هر دو مورد**

```js run
for (let i = 0; i < 5; ++i) alert( i );

for (let i = 0; i < 5; i++) alert( i );
```

That can be easily deducted from the algorithm of `for`:
می توان به آسانی از الگوریتم `for` آن را فهمید:

1. Execute once `i = 0` before everything (begin).
2. Check the condition `i < 5`
3. If `true` -- execute the loop body `alert(i)`, and then `i++`
1. یک بار `i = 0` را قبل از هر چیزی اجرا می کند(در شروع).
2. شرط `i < 5` را بررسی می کند
3. اگر `true` باشد -- بدنه ی حلقه `alert(i)` اجرا می شود، و سپس `i++`

The increment `i++` is separated from the condition check (2). That's just another statement.
افزایش `i++` از بررسی شرط جداگانه است(2). آن فقط یک دستور جدا است.

The value returned by the increment is not used here, so there's no difference between `i++` and `++i`.
مقدار برگردانده شده توسط increment اینجا استفاده نمی شود، پس تفاوتی بین `i++` و `++i` نیست.
10 changes: 5 additions & 5 deletions 1-js/02-first-steps/13-while-for/3-which-value-for/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ importance: 4

---

# Which values get shown by the "for" loop?
# کدام مقدارها توسط حلقه "for" نمایش داده می شوند؟

For each loop write down which values it is going to show. Then compare with the answer.
برای هر حلقه یادداشت کنید که چه مقداری را نمایش خواهد داد. سپس با جواب مقایسه کنید.

Both loops `alert` same values or not?
هر دو حلقه مقدارهای مشابه را `alert` می کنند یا نه؟

1. The postfix form:
1. شکل پسوند:

```js
for (let i = 0; i < 5; i++) alert( i );
```
2. The prefix form:
2. شکل پیشوند:

```js
for (let i = 0; i < 5; ++i) alert( i );
Expand Down
2 changes: 1 addition & 1 deletion 1-js/02-first-steps/13-while-for/4-for-even/solution.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ for (let i = 2; i <= 10; i++) {
}
```

We use the "modulo" operator `%` to get the remainder and check for the evenness here.
ما اینجا از عملگر "modulo" `%` برای گرفتن باقی مانده و بررسی زوج بودن استفاده می کنیم.
6 changes: 3 additions & 3 deletions 1-js/02-first-steps/13-while-for/4-for-even/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ importance: 5

---

# Output even numbers in the loop
# اعداد زوج را در حلقه خروجی بدهید

Use the `for` loop to output even numbers from `2` to `10`.
از حلقه `for` برای خروجی دادن اعداد زوج بین `2` و `10` استفاده کنید.

[demo]
[دمو]
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
```js run
let i = 0;
while (i < 3) {
alert( `number ${i}!` );
alert( `عدد ${i}!` );
i++;
}
```
Expand Down
6 changes: 3 additions & 3 deletions 1-js/02-first-steps/13-while-for/5-replace-for-while/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ importance: 5

---

# Replace "for" with "while"
# "for" را با "while" جایگزین کنید

Rewrite the code changing the `for` loop to `while` without altering its behavior (the output should stay same).
کد را با تغییر حلقه `for` به `while` بدون عوض کردن رفتار آن دوباره بنویسید (خروجی باید یکسان بماند).

```js run
for (let i = 0; i < 3; i++) {
alert( `number ${i}!` );
alert( `عدد ${i}!` );
}
```

Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
let num;

do {
num = prompt("Enter a number greater than 100?", 0);
num = prompt("عددی بزرگ تر از 100 وارد کنید.", 0);
} while (num <= 100 && num);
```

The loop `do..while` repeats while both checks are truthy:
حلقه `do..while` تا زمانی که هر دو بررسی truthy باشند تکرار می شود:

1. The check for `num <= 100` -- that is, the entered value is still not greater than `100`.
2. The check `&& num` is false when `num` is `null` or an empty string. Then the `while` loop stops too.
1. بررسی `num <= 100` -- به این معنی است که مقدار وارد شده هنوز از `100` بزرگ تر نیست.
2. بررسی `&& num` زمانی که `num` برابر با `null` یا یک رشته خالی باشد اشتباه است. سپس حلقه `while` هم متوقف می شود.

P.S. If `num` is `null` then `num <= 100` is `true`, so without the 2nd check the loop wouldn't stop if the user clicks CANCEL. Both checks are required.
ضمیمه: اگر `num` برابر با `null` باشد سپس `num <= 100` برابر با `true` است، پس بدون بررسی دوم اگر کاربر روی CANCEL کلیک کند حلقه متوقف نمی شود. هر دو بررسی مورد نیاز هستند.
10 changes: 5 additions & 5 deletions 1-js/02-first-steps/13-while-for/6-repeat-until-correct/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ importance: 5

---

# Repeat until the input is correct
# تا زمانی که ورودی درست باشد تکرار کنید

Write a loop which prompts for a number greater than `100`. If the visitor enters another number -- ask them to input again.
یک حلقه بنویسید که برای یک عدد بزرگ تر از `100` prompt می کند. اگر بازدیدکننده عدد دیگری وارد کرد -- دوباره از او بخواهید که وارد کند.

The loop must ask for a number until either the visitor enters a number greater than `100` or cancels the input/enters an empty line.
حلقه باید برای یک عدد درخواست کند مگر اینکه بازدیدکننده یک عدد بزرگ تر از `100` وارد کند یا ورودی گرفتن را لغو کند / یک خط خالی وارد کند.

Here we can assume that the visitor only inputs numbers. There's no need to implement a special handling for a non-numeric input in this task.
اینجا ما می توانیم فرض کنیم که بازدیدکننده فقط عدد وارد می کند. در این تمرین نیازی به پیاده سازی بررسی خاصی برای ورودی غیر عددی نیست.

[demo]
[دمو]
14 changes: 7 additions & 7 deletions 1-js/02-first-steps/13-while-for/7-list-primes/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ importance: 3

---

# Output prime numbers
# اعداد اول را خروجی بدهید

An integer number greater than `1` is called a [prime](https://en.wikipedia.org/wiki/Prime_number) if it cannot be divided without a remainder by anything except `1` and itself.
یک عدد صحیح بزرگ تر از 1 زمانی [اول](https://fa.wikipedia.org/wiki/عدد_اول) صدا زده می شود که نتوان آن را به هر چیزی بدون اینکه باقی مانده داشته باشد تقسیم کرد به جز `1` و خودش.

In other words, `n > 1` is a prime if it can't be evenly divided by anything except `1` and `n`.
به عبارتی دیگر، `n > 1` یک عدد اول است اگر نتواند با هیچ چیزی به جز `1` و `n` به صورت مساوی تقسیم شود.

For example, `5` is a prime, because it cannot be divided without a remainder by `2`, `3` and `4`.
برای مثال، `5` یک عدد اول است، چون نمی تواند بدون باقی مانده به `2`، `3` و `4` تقسیم شود.

**Write the code which outputs prime numbers in the interval from `2` to `n`.**
**کدی بنویسید که اعداد اول را در بازه `2` تا `n` خروجی بدهد**

For `n = 10` the result will be `2,3,5,7`.
برای `n = 10` نتیجه `7 ،5 ،3 ،2` خواهد بود.

P.S. The code should work for any `n`, not be hard-tuned for any fixed value.
ضمیمه: کد باید برای هر مقدار `n` کار کند، نه اینکه برای مقدار مشخصی تنظیم شده باشد.
Loading