Challenge: Print Numbers Sequentially

This challenge will test your skills in implementing async/await with promises in JavaScript.

Problem statement #

In this challenge, you need to print the numbers 0-9 in a sequential manner, so that each number is printed after a random waiting time. For example, i=0 might wait 4 seconds before being printed, whereas i=1 might wait 2 seconds before being printed. You need to use the sleep function (given below) to achieve this. However, it will cause values to be printed in a non-sequential manner. Your task is to write the code in a way that the values are printed in a sequential manner.

You need to implement the concept of async/await in this exercise.

Input #

print function

Output #

Displaying numbers from 0-9 sequentially

Sample input #

print()

Sample output #

0
1
2
3
4
5
6
7
8
9

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.