mercredi 6 novembre 2019

JavaScript. Math.random is not work as expected [on hold]

When I run next code I expect to see random numbers.

function randomPromise() {
        const time = Math.round(Math.random() * 100);
    
        return new Promise(resolve => {
            setTimeout(() => resolve(time), time);
        })
    }
    
for (let i = 0; i < 10; i++) {
    randomPromise().then(console.log);
}

But if you run this you'll see something like this:

8
12
15
15
20
66
67
69
78
87



Aucun commentaire:

Enregistrer un commentaire