Blondinka, есть же
reduce для этого
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<button onclick="sumArray()">Try it</button>
<p id="demo"></p>
<p id="result"></p>
<script>
var variablesArray = [];
function sum(arr) {
return arr.reduce(function(prev, next) {
return prev + next;
});
}
function sumArray() {
for(var i = 0; i < 5; i++){
variablesArray.push( Math.round(Math.random()* 10));
}
document.getElementById("demo").innerHTML = variablesArray;
document.getElementById("result").innerHTML = sum(variablesArray);
}
</script>
</body>
</html>