var x = 0; function num(n) { if (n >= 0 && n <= 9) return x++; return num(n / 10, x++); } alert(num(223));