Output every second
importance: 5
Write a function printNumbers(from, to) that outputs a number every second, starting from from and ending with to.
Make two variants of the solution.
- Using
setInterval. - Using nested
setTimeout.
Using setInterval:
Using nested setTimeout:
Note that in both solutions, there is an initial delay before the first output. The function is called after 1000ms the first time.
If we also want the function to run immediately, then we can add an additional call on a separate line, like this: