File tree Expand file tree Collapse file tree 5 files changed +134
-136
lines changed
1-js/06-advanced-functions/08-settimeout-setinterval Expand file tree Collapse file tree 5 files changed +134
-136
lines changed Original file line number Diff line number Diff line change 1
1
2
- Using ` setInterval ` :
2
+ Usando ` setInterval ` :
3
3
4
4
``` js run
5
5
function printNumbers (from , to ) {
@@ -14,12 +14,11 @@ function printNumbers(from, to) {
14
14
}, 1000 );
15
15
}
16
16
17
- // usage :
17
+ // uso :
18
18
printNumbers (5 , 10 );
19
19
```
20
20
21
- Using nested ` setTimeout ` :
22
-
21
+ Usando ` setTimeout ` anidado:
23
22
24
23
``` js run
25
24
function printNumbers (from , to ) {
@@ -34,13 +33,13 @@ function printNumbers(from, to) {
34
33
}, 1000 );
35
34
}
36
35
37
- // usage :
36
+ // uso :
38
37
printNumbers (5 , 10 );
39
38
```
40
39
41
- Note that in both solutions, there is an initial delay before the first output. The function is called after ` 1000ms ` the first time .
40
+ Tenga en cuenta que en ambas soluciones, hay un retraso inicial antes de la primera salida. La función se llama después de ` 1000ms ` la primera vez .
42
41
43
- If we also want the function to run immediately, then we can add an additional call on a separate line, like this :
42
+ Si también queremos que la función se ejecute inmediatamente, entonces podemos agregar una llamada adicional en una línea separada, como esta :
44
43
45
44
``` js run
46
45
function printNumbers (from , to ) {
Original file line number Diff line number Diff line change @@ -2,11 +2,11 @@ importance: 5
2
2
3
3
---
4
4
5
- # Output every second
5
+ # Salida cada segundo
6
6
7
- Write a function ` printNumbers(from, to) ` that outputs a number every second, starting from ` from ` and ending with ` to ` .
7
+ Escriba una función ` printNumbers(from, to) ` que genere un número cada segundo, comenzando desde ` from ` y terminando con ` to ` .
8
8
9
- Make two variants of the solution .
9
+ Haz dos variantes de la solución .
10
10
11
- 1 . Using ` setInterval ` .
12
- 2 . Using nested ` setTimeout ` .
11
+ 1 . Usando ` setInterval ` .
12
+ 2 . Usando ` setTimeout ` anidado .
Original file line number Diff line number Diff line change 1
1
2
- Any ` setTimeout ` will run only after the current code has finished .
2
+ Cualquier ` setTimeout ` se ejecutará solo después de que el código actual haya finalizado .
3
3
4
- The ` i ` will be the last one: ` 100000000 ` .
4
+ La ` i ` será la última: ` 100000000` .
5
5
6
6
``` js run
7
7
let i = 0 ;
8
8
9
9
setTimeout (() => alert (i), 100 ); // 100000000
10
10
11
- // assume that the time to execute this function is >100ms
11
+ // supongamos que el tiempo para ejecutar esta función es> 100 ms
12
12
for (let j = 0 ; j < 100000000 ; j++ ) {
13
13
i++ ;
14
14
}
Original file line number Diff line number Diff line change @@ -2,25 +2,25 @@ importance: 5
2
2
3
3
---
4
4
5
- # What will setTimeout show ?
5
+ # ¿Qué mostrará setTimeout?
6
6
7
- In the code below there's a ` setTimeout ` call scheduled, then a heavy calculation is run, that takes more than 100ms to finish .
7
+ En el siguiente código hay una llamada programada ` setTimeout ` , luego se ejecuta un cálculo pesado, que demora más de 100 ms en finalizar .
8
8
9
- When will the scheduled function run ?
9
+ ¿Cuándo se ejecutará la función programada ?
10
10
11
- 1 . After the loop .
12
- 2 . Before the loop .
13
- 3 . In the beginning of the loop .
11
+ 1 . Después del bucle .
12
+ 2 . Antes del bucle .
13
+ 3 . Al comienzo del bucle .
14
14
15
15
16
- What is ` alert ` going to show ?
16
+ ¿Qué va a mostrar "alerta" ?
17
17
18
18
``` js
19
19
let i = 0 ;
20
20
21
21
setTimeout (() => alert (i), 100 ); // ?
22
22
23
- // assume that the time to execute this function is >100ms
23
+ // supongamos que el tiempo para ejecutar esta función es> 100 ms
24
24
for (let j = 0 ; j < 100000000 ; j++ ) {
25
25
i++ ;
26
26
}
You can’t perform that action at this time.
0 commit comments