+ 1

Digit Number Javascript (Help me please)

Do you guys know the javascript method to add up the number digits? For example I have: var number = 1234; , I want to add that digit.

14th Jun 2018, 10:36 AM
Nufik
Nufik - avatar
1 Respuesta
+ 3
var number = 1234; var sum = 0; while (number>0){ sum+=number%10; number/=10; number = floor(number); }
14th Jun 2018, 10:45 AM
Alexandru Turculet
Alexandru Turculet - avatar