Skip to content

Instantly share code, notes, and snippets.

@dement6d
dement6d / sleep.js
Created May 15, 2022 01:16
Javascript sleep function with fancy output
function sleep(time) {
console.log(
'Sleeping for ' + (
time < 1000
? time + ((time == 1) ? "millisecond" : " milliseconds")
: time >= 60000
? (time >= 3600000)
? (time/3600000).toFixed(3) + (((time/3600000).toFixed(0) == 1) ? " hour" : " hours")
: ((time/1000)/60).toFixed(3) + (((time/1000)/60).toFixed(0) == 1 ? " minute" : " minutes")
: (time/1000).toFixed(3) + ((time/1000).toFixed(0) == 1 ? " second" : " seconds")