JavaScript Program to Find Sum of digits of a given number

Write a JavaScript program to find sum of digits of a given number.

For example, if number is 453 then 4 + 5 + 3 = 12.



Source Code
<html>
<head>
	<title>Sum of digits of a number</title>
</head>
<body>
<script>

	var n = parseInt(prompt("Enter the number", ""));
  var sum_of_digits = 0;
  
  while(n > 0)
  {
    sum_of_digits = sum_of_digits + (n%10);
    n = parseInt(n / 10);
  }
  document.write("Sum of digits of given number is : " + sum_of_digits);
 
</script>
</body>
</html>
Output