Left padding
I don't do much JavaScript, but is this really the most efficient way to pad a string from the left? What's wrong with a repeat string function then right(lengthNeeded)? This looks like something copied from a BASIC tutorial 20 years ago.