Solution Review: Print Numbers Sequentially
This lesson will explain the solution to the problem in the previous lesson.
Solution #
Press + to interact
const sleep = (i,ms) => new Promise(resolve => setTimeout(() => resolve(i), ms));async function print() {for (let i = 0; i < 10; i++) {await sleep(i,Math.random()*1000).then(function(result){console.log(result)})}}print()
Explanation #
Let’s look at the sleep
function first.
const sleep = (i,ms) => new Promise(resolve => setTimeout(() => resolve(i), ms));
It takes two parameters: i
and ms
, the latter of which is the time in ...
Access this course and 1400+ top-rated courses and projects.