Skip to content

Commit dc1aaa2

Browse files
committed
translated tasks, solutions & index.md
1 parent 8b70f9c commit dc1aaa2

File tree

13 files changed

+59
-73
lines changed

13 files changed

+59
-73
lines changed
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
2-
31
```js run demo
42
let a = +prompt("The first number?", "");
53
let b = +prompt("The second number?", "");
64

75
alert( a + b );
86
```
97

10-
Note the unary plus `+` before `prompt`. It immediately converts the value to a number.
8+
توجه کنید که جمع واحد `+` قبل از `prompt` است. این یعنی در همان لحظه به مقدار عددی تبدیل می‌شود.
119

12-
Otherwise, `a` and `b` would be string their sum would be their concatenation, that is: `"1" + "2" = "12"`.
10+
در غیر اینصورت، `a` و `b`، رشته حرفی میبودند و جمع آنها، پیوست کردن آنها به یکدیگر می‌بود که یعنی:‌ `"1" + "2" = "12"`.

1-js/05-data-types/02-number/1-sum-interface/task.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ importance: 5
22

33
---
44

5-
# Sum numbers from the visitor
5+
# اعداد را جمع کنید
66

7-
Create a script that prompts the visitor to enter two numbers and then shows their sum.
7+
کدی بنویسید که از بازدیدکننده درخواست میکند دو عدد را وارد کند و سپس جمع آنهارا نشان دهد.
88

99
[demo]
1010

11-
P.S. There is a gotcha with types.
11+
پی نوشت: حواستان به مدل‌های داده‌ها باشد.

1-js/05-data-types/02-number/2-why-rounded-down/solution.md

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,27 @@
1-
Internally the decimal fraction `6.35` is an endless binary. As always in such cases, it is stored with a precision loss.
2-
3-
Let's see:
1+
در درون سیستم، یک عدد دودویی `6.35` بی‌پایان است. مثل همیشه، در این حالات با یک دقت از دست رفته‌ای ذخیره خواهد شد.
42

53
```js run
64
alert( 6.35.toFixed(20) ); // 6.34999999999999964473
75
```
86

9-
The precision loss can cause both increase and decrease of a number. In this particular case the number becomes a tiny bit less, that's why it rounded down.
10-
11-
And what's for `1.35`?
7+
این از دست دادن دقت می‌تواند در هم مقدار عدد را افزایش یا کاهش دهد. در این حالت خاص، عدد اندکی کوچک می‌شود، به همین علت به پایین رند می‌شود.
128

9+
و اما `1.35` چی؟
1310
```js run
1411
alert( 1.35.toFixed(20) ); // 1.35000000000000008882
1512
```
1613

17-
Here the precision loss made the number a little bit greater, so it rounded up.
14+
اینجا از دست دادن دقت باعث شد عدد اندکی بزرگتر شود، پس به بالا رند می‌شود.
1815

19-
**How can we fix the problem with `6.35` if we want it to be rounded the right way?**
16+
**چطور میتوانیم مشکل `6.35` را حل کنیم اگر بخواهیم که درست رند شود؟**
2017

21-
We should bring it closer to an integer prior to rounding:
18+
باید به عدد صحیح نزدیک قبلی‌ش رندش کنیم:
2219

2320
```js run
2421
alert( (6.35 * 10).toFixed(20) ); // 63.50000000000000000000
2522
```
2623

27-
Note that `63.5` has no precision loss at all. That's because the decimal part `0.5` is actually `1/2`. Fractions divided by powers of `2` are exactly represented in the binary system, now we can round it:
28-
24+
توجه داشته باشید که `63.5` هیچ از دست دادن دقتی ندارد. به خاطر قسمت اعشاری آن `0.5` که در اصل `1/2` است. کسرهای تقسیم شده بر دو به درستی در سیستم دودویی نمایش داده می‌شوند، حالا میتوانیم آن را رند کنیم:
2925

3026
```js run
3127
alert( Math.round(6.35 * 10) / 10); // 6.35 -> 63.5 -> 64(rounded) -> 6.4

1-js/05-data-types/02-number/2-why-rounded-down/task.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,19 @@ importance: 4
22

33
---
44

5-
# Why 6.35.toFixed(1) == 6.3?
5+
# چرا 6.35.toFixed(1) == 6.3?
66

7-
According to the documentation `Math.round` and `toFixed` both round to the nearest number: `0..4` lead down while `5..9` lead up.
87

9-
For instance:
8+
بنابر مستندات `Math.round` و `toFixed`، هردو به نزدیکترین عدد آن را رند میکنند: `0..4` به پایین رند میشود و `5..9` به بالا.
109

10+
به عنوان مثال:
1111
```js run
1212
alert( 1.35.toFixed(1) ); // 1.4
1313
```
1414

15-
In the similar example below, why is `6.35` rounded to `6.3`, not `6.4`?
16-
15+
در مثال مشابه زیر، چرا `6.35` به `6.3` رند میشود، نه `6.4`؟
1716
```js run
1817
alert( 6.35.toFixed(1) ); // 6.3
1918
```
2019

21-
How to round `6.35` the right way?
22-
20+
چطور `6.35` را رند کنیم؟

1-js/05-data-types/02-number/3-repeat-until-number/solution.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ function readNumber() {
1515
alert(`Read: ${readNumber()}`);
1616
```
1717

18-
The solution is a little bit more intricate that it could be because we need to handle `null`/empty lines.
18+
جواب اندکی پیچیده‌ست که به خاطر این است که باید `null`/خالی را هم در نظر بگیریم.
1919

20-
So we actually accept the input until it is a "regular number". Both `null` (cancel) and empty line also fit that condition, because in numeric form they are `0`.
21-
22-
After we stopped, we need to treat `null` and empty line specially (return `null`), because converting them to a number would return `0`.
20+
پس ما تا وقتی ورودی را می‌پذیریم که عدد عادی باشد. هردوی `null` (cancel) و خط خالی هم در این شرایط میگنجد، چونکه در فرم عددی صفر هستند.
2321

22+
بعد از اینکه برنامه متوقف شد بایستی `null` و مخصوصا خط‌های خالی (خروجی `null`) را در نظر بگیریم، چون تبدیل آنها به عدد صفر برمی‌گرداند.

1-js/05-data-types/02-number/3-repeat-until-number/task.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ importance: 5
22

33
---
44

5-
# Repeat until the input is a number
5+
# تا زمانی که ورودی یک عدد است تکرار کن
66

7-
Create a function `readNumber` which prompts for a number until the visitor enters a valid numeric value.
7+
یک تابع `readNumber` بسازید که تا زمانی که بازدیدکننده یک عدد وارد نکرده باشد، نرود.
88

9-
The resulting value must be returned as a number.
10-
11-
The visitor can also stop the process by entering an empty line or pressing "CANCEL". In that case, the function should return `null`.
9+
خروجی به فرمت عدد باید باشد.
1210

11+
بازدید کننده میتواند با وارد کردن یک خط خالی یا فشردن دکمه‌ی "CANCEL" پردازش را متوقف کند. در این حالت، تابع خروجی `null` را می‌دهد.
1312
[demo]
1413

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
That's because `i` would never equal `10`.
2-
3-
Run it to see the *real* values of `i`:
1+
به این علت است که `i` هیچوقت برابر ده نمیشود.
42

3+
این تکه کد را اجرا کنید تا مقدار حقیقی `i` را ببینید:
54
```js run
65
let i = 0;
76
while (i < 11) {
@@ -10,8 +9,9 @@ while (i < 11) {
109
}
1110
```
1211

13-
None of them is exactly `10`.
1412

15-
Such things happen because of the precision losses when adding fractions like `0.2`.
13+
هیچکدام از آنها دقیقا ده نیست.
14+
15+
چنین اتفاقاتی به علت از دست رفتن دقت در حین جمع کردن کسرهایی مثل `0.2` رخ می‌دهد.
1616

17-
Conclusion: evade equality checks when working with decimal fractions.
17+
نتیجه: وقتی با کسرهای اعشاری کار میکنید، از تساوی استفاده نکنید.

1-js/05-data-types/02-number/4-endless-loop-error/task.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ importance: 4
22

33
---
44

5-
# An occasional infinite loop
6-
7-
This loop is infinite. It never ends. Why?
5+
# یک حلقه‌ی بی‌نهایت
86

7+
این حلقه بی‌نهایت است. هیچوقت تمام نمی‌شود. چرا؟
98
```js
109
let i = 0;
1110
while (i != 10) {

1-js/05-data-types/02-number/8-random-min-max/solution.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
We need to "map" all values from the interval 0..1 into values from `min` to `max`.
1+
نیاز داریم که تمام مقادیر را در بازه 0..1 به مقادیر از `min` تا `max` ارتباط دهیم.
22

3-
That can be done in two stages:
3+
این به دو روش قابل انجام است:
44

5-
1. If we multiply a random number from 0..1 by `max-min`, then the interval of possible values increases `0..1` to `0..max-min`.
6-
2. Now if we add `min`, the possible interval becomes from `min` to `max`.
5+
۱. اگر یک عدد تصادفی از 0..1 را در عددی `max-min` ضرب کنیم، بازه‌ی مقادیر ممکن از `0..1` به `0..max-min` افزایش می‌یابد.
76

8-
The function:
7+
۲. حالا اگر `min` را اضافه کنیم، بازه‌ی ممکن از `min` تا `max` میشود.
98

9+
تابع:
1010
```js run
1111
function random(min, max) {
1212
return min + Math.random() * (max - min);

1-js/05-data-types/02-number/8-random-min-max/task.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ importance: 2
22

33
---
44

5-
# A random number from min to max
5+
# عددی تصادفی از بین مینیمم تا ماکسیمم
66

7-
The built-in function `Math.random()` creates a random value from `0` to `1` (not including `1`).
7+
تابع از پیش آماده شده‌ی `Math.random()`، یک مقدار تصادفی از `0` تا `1` میسازد (به جز خود یک).
88

9-
Write the function `random(min, max)` to generate a random floating-point number from `min` to `max` (not including `max`).
9+
تابع `random(min, max)` را بنویسید که یک عدد اعشاری از بین `min` تا`max` را می‌سازد (به جز خود `max`).
1010

11-
Examples of its work:
11+
مثال‌هایی ازینکه چگونه کار می‌کند:
1212

1313
```js
1414
alert( random(1, 5) ); // 1.2345623452

0 commit comments

Comments
 (0)