Scheduling: setTimeout and setInterval by vplentinax · Pull Request #202 · javascript-tutorial/es.javascript.info · GitHub
Skip to content
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
Expand Up @@ -2,11 +2,11 @@ importance: 5

---

# Output every second
# Salida cada segundo

Write a function `printNumbers(from, to)` that outputs a number every second, starting from `from` and ending with `to`.
Escriba una función `printNumbers(from, to)` que genere un número cada segundo, comenzando desde `from` y terminando con `to`.

Make two variants of the solution.
Haz dos variantes de la solución.

1. Using `setInterval`.
2. Using nested `setTimeout`.
1. Usando `setInterval`.
2. Usando `setTimeout` anidado.
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.
Cualquier `setTimeout` se ejecutará solo después de que el código actual haya finalizado.

The `i` will be the last one: `100000000`.
La `i` será la última:` 100000000`.

```js run
let i = 0;

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

// assume that the time to execute this function is >100ms
// supongamos que el tiempo para ejecutar esta función es> 100 ms
for(let j = 0; j < 100000000; j++) {
i++;
}
Expand Down
Loading