JavaScript Program to Display Sum and Product of Array Elements

Write a JavaScript program to display sum and product of array elements.



Source Code
<html>
<head>
    <title>Display sum and product of array elements</title>
    <script type="text/javascript">
        var arr = [13, 56, 7, 23, 1, 7, 8];
        var sum=0, product = 1;

        for(var i=0; i<arr.length; i++) 
        {
            sum += arr[i];
            product *= arr[i];    
        }
        document.write("Array elements are " + arr + "<br />");
        document.write("<h3>Sum : " + sum + "</h3>");
        document.write("<h3>Product : " + product + "</h3>");
    </script>
</head>
<body>

</body>
</html>
Output





"Coding Hub - Learn to code" app now available on Google Play Store