28. JavaScript Program to find out Sum of Even and Product of Odd digits of given 6 digit Number.
How does this program work?
- This program is used to find out Sum of Even and Product of Odd digits in the given 6 digit Number using PHP.
- In this program odd and even A number is even if it is perfectly divisible by 2.
- When the number is divided by 2, we use the remainder operator % to compute the remainder.
- If the remainder is zero, the number is even then sum will be executes else the number is odd then product will be executed by using given logic.
Here is the code
<html>
<head>
<title>JavaScript program to find the Sum of even and Product of odd digits of given 6 digit number</title>
</head>
<body>
<table>
<tr>
<td> <input type="text" name="a" id="first" placeholder="Enter any 6 digit number" maxlength="6"> </td>
</tr>
<tr>
<td> <button onclick="sum_product6 ()" >Submit</button> </td>
</tr>
</table>
<div id = "num"></div>
<div id = "num1"></div>
</body>
<script type="text/javascript">
function sum_product6()
{
var r,n,sum = 0, product = 1;
n = parseInt(document.getElementById ("first").value);
n1 = n;
while(n > 0)
{
r = n%10;
if(r%2 == 0)
{
sum = sum+r;
}
else
{
product =product*r;
}
n = parseInt(n/10);
}
document.getElementById ("num").innerHTML= "Sum of even digits : "+sum;
document.getElementById ("num1").innerHTML= "Product of odd digits : "+product;
}
</script>
</html>