Skip to content

Instantly share code, notes, and snippets.

@laroi
laroi / getRandProgress.js
Last active January 31, 2019 13:10
Gets random fake progress bar values for JS
getRandomProgress = () => {
let secs = 0; // How many seconds to wait
let perc = 0; // How much percentage to update
let func = () => {
if (perc < 100 ) { // Exit the loop if we reached 100
perc = Math.min((perc + Math.floor(Math.random() * 40)), 100); //Get the random percentage, make sure it is less than 100
secs += Math.ceil(Math.random()*2); // Get random Time
(function(_perc, _secs) {
return setTimeout(function(){/*update dom here*/console.log(_perc, _secs)}, _secs*1000);
})(perc, secs)