function two(a) { return (9 < a ? "" : "0") + a }; alert(two(9)); alert(two(19)); function two(a) { return ("0" + a).slice(-2) }; alert(two(9)); alert(two(19));