I want the user to enter a number and print back the amount of digits of that number.
I know that I can use length
, but my homework asking for while
loop.
This is what I have so far:
var num;
var count = 0;
num = prompt('Enter number: ');
function counter(x, y) {
while (x > 0) {
y++;
x /= 10;
}
return y;
}
var result = counter(num, count);
console.log(result);
When I give the number 3456
(example), I get back the number 328
. I want it to print back the number 4
.