Find Number of Digits in Number // Edabit

PHOTO EMBED

Tue Dec 26 2023 08:49:13 GMT+0000 (Coordinated Universal Time)

Saved by @msagr

function num_of_digits(num) {
	let cnt = 1;
	num = Math.abs(num);
	num = Math.floor(num/10);
	while(num != 0){
		cnt = cnt+1;
		num = Math.floor(num/10);
	}
	return cnt;
}
content_copyCOPY

Note :- will have to use Math.floor(num), to round down the number, don't confuse with concept used in languages like C ; where int/int gives int.

https://edabit.com/challenges/javascript