I'm trying to count the digits of a number and I found this function
function countDigits(y){
num = parseInt(y)
count = 0
if (num >= 1)
++count;
while (num / 10 >= 1) {
num /= 10;
++count;
}
return count;
}
console.log(countDigits("123456"));
console.log(countDigits("1"));
console.log(countDigits("012"));
I'm taking the input from a string digit y.
The problem with the function is when a number starts with a zero it doesn't count it?
y.length)?