Number.prototype.pad = function(length) { var res = this.toString(); while (res.length < length) res = '0' + res; return res; }; for (var i = 0; i < 999; i++) { document.write( '<img src='+i.pad(3)+'.jpg><br><br>'); }