FY B.sc IT Practical 3(D) : Write a JavaScript program to accept a number from the user and display the sum of its digits.

 <!DOCTYPE html>

<html>

<head>

<title>sum of digits</title>

<script>

var n=parseInt(prompt("Enter the number"," "));

var p=0,y;

while(n>0)

{

y=n%10;

n=parseInt(n/10);

p=p+y;

}

document.write("Sum of digits is: "+p);

</script>

</head>

</html>


Comments

Popular posts from this blog

Create an android app that demonstrates Activity Lifecycle and Instance State.

Program using Light Sensitive Sensors on Tinkercad