Finding Things

Variation 2 on the first exercise, JavaScript 2,

by GOLDENSWORD559

HTML

<script src="http://wilderland.org/javascript2/findAverageTest.js"></script>
<div class='explanation'>
    The tests in this fiddle expect a function called "findAverage". The tests will pass the function an array of numbers.  The function should return the average of all the values in the array.
    <p>
        Recall that the <i>average</i> of a set of numbers is the sum of the numbers divided by how many there are. So, the average of <code>[ 1, 3, 5 ]</code> is 3, because <code>1 + 3 + 5</code> is 9, and 9 divided by 3 is 3.
</div>
<button>Click To Run Tests</button>
<div id=results></div>

CSS

.explanation {
    border: 1px solid #010310;
    border-radius: 10px;
    box-shadow: 2px 2px 3px rgba(12,10,30,0.3);
    margin: 10px 0 20px 5px;
    font-family: sans-serif;
    
    padding: 15px;
    width: 30em;
}

p {
  margin-top: 5px;
}

JavaScript

function findAverage(list) {
    var i, current, sum = 0;
    for (var i = 0; i < list.length; ++i) {
        current = list[i]; //finds numbers in list form
                                            
        sum = sum+current;        //appends current number to array
                        //sums array, needs work
          
    }
    return sum/list.length;
}