Run ❯
Get your
own
website
Result Size:
625 x 565
×
Change Orientation
Save Code
Change Theme, Dark/Light
Go to Spaces
<!DOCTYPE html> <html> <body> <h2>JavaScript Arrays</h2> <p>Compute the sum of the rounded numbers in an array.</p> <p id="demo"></p> <script> const numbers = [15.5, 2.3, 1.1, 4.7]; document.getElementById("demo").innerHTML = numbers.reduce(getSum, 0); function getSum(total, num) { return total + Math.round(num); } </script> </body> </html>