HTML Editor
<!DOCTYPE html> <html lang="en-US"> <body> <h1>JS Sum of Digits</h1> <script> var num = 12345; var copyNum = num; var total = 0; //Add Each digit from last digit. while(copyNum != 0) { total += copyNum % 10; copyNum = Math.floor(copyNum / 10); } //result document.write("The sum of digit " +num +" is " +total); </script> </body> </html>
OUTPUT
×

Save as Private