Skip to content
Merged
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

Using `setInterval`:
با استفاده از `setInterval`:

```js run
function printNumbers(from, to) {
Expand All @@ -14,11 +14,11 @@ function printNumbers(from, to) {
}, 1000);
}

// usage:
// :کاربرد
printNumbers(5, 10);
```

Using nested `setTimeout`:
با استفاده از `setTimeout` تودرتو:


```js run
Expand All @@ -34,13 +34,13 @@ function printNumbers(from, to) {
}, 1000);
}

// usage:
// :کاربرد
printNumbers(5, 10);
```

Note that in both solutions, there is an initial delay before the first output. The function is called after `1000ms` the first time.
در نظر داشته باشید که در هر دو راه‌حل، یک تاخیر اولیه قبل از اولین خروجی وجود دارد. تابع بعد `1000 میلی‌ثانیه` از اولین بار فراخوانی می‌شود.

If we also want the function to run immediately, then we can add an additional call on a separate line, like this:
اگر ما بخواهیم که تابع بلافاصله اجرا شود، سپس می‌توانیم یک فراخوانی اضافی در خطی جداگانه اضافه کنیم، مثل اینجا:

```js run
function printNumbers(from, to) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ importance: 5

---

# Output every second
# در هر ثانیه خروجی بگیرید

Write a function `printNumbers(from, to)` that outputs a number every second, starting from `from` and ending with `to`.
یک تابع `printNumbers(from, to)` بنویسید که هر ثانیه یک عدد را نمایش می‌دهد که از `from` شروع می‌شود و با `to` پایان می‌یابد.

Make two variants of the solution.
دو نوع راه‌حل بسازید.

1. Using `setInterval`.
2. Using nested `setTimeout`.
1. با استفاده از `setInterval`.
2. با استفاده از `setTimeout` تودرتو.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@

Any `setTimeout` will run only after the current code has finished.
هر تابع `setTimeout` فقط بعد از اینکه کد کنونی تمام شود اجرا می‌شود.

The `i` will be the last one: `100000000`.
متغیر `i` آخرین خواهد بود: `100000000`.

```js run
let i = 0;

setTimeout(() => alert(i), 100); // 100000000

// assume that the time to execute this function is >100ms
// فرض کنیم که زمان اجرای این تابع بیشتر از 100 میلی‌ثانیه است
for(let j = 0; j < 100000000; j++) {
i++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@ importance: 5

---

# What will setTimeout show?
# تابع setTimeout چه چیزی را نمایش خواهد داد?

In the code below there's a `setTimeout` call scheduled, then a heavy calculation is run, that takes more than 100ms to finish.
در کد پایین یک فراخوانی `setTimeout` زمان‌بندی شده وجود دارد سپس یک محاسبات سنگین اجرا می‌شود که بیشتر از 100 میلی‌ثانیه طول می‌کشد تا تمام شود.

When will the scheduled function run?
تابع زمان‌بندی شده چه زمانی اجرا می‌شود؟

1. After the loop.
2. Before the loop.
3. In the beginning of the loop.
1. بعد از حلقه.
2. قبل از حلقه.
3. در آغاز حلقه.


What is `alert` going to show?
قرار است `alert` چه چیزی را نمایش دهد؟

```js
let i = 0;

setTimeout(() => alert(i), 100); // ?

// assume that the time to execute this function is >100ms
// فرض کنیم که زمان اجرای این تابع بیشتر از 100 میلی‌ثانیه است
for(let j = 0; j < 100000000; j++) {
i++;
}
Expand Down
Loading