Skip to content

Instantly share code, notes, and snippets.

@jbfink
Created February 10, 2012 20:05
Show Gist options
  • Save jbfink/1792359 to your computer and use it in GitHub Desktop.
Save jbfink/1792359 to your computer and use it in GitHub Desktop.
codeyear week5, timetrials 2
// runner times
var carlos = [9.6,10.6,11.2,10.3,11.5];
var sarah = [10.6,11.2,9.4,12.3,10.1];
var timothy = [12.2,11.8,12.5,10.9,11.1];
var calculateAverage = function (raceTimes) {
var totalTime;
for ( i = 0; i < raceTimes.length; i++ ) {
totalTime = (totalTime || 0) + raceTimes[i];
// assign variable averageTime
}
var averageTime = totalTime / raceTimes.length;
return averageTime;
};
// write the result of your function call console.log()
console.log(calculateAverage(timothy));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment