Skip to content

Instantly share code, notes, and snippets.

@Jared-Prime
Created April 12, 2012 21:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jared-Prime/2371299 to your computer and use it in GitHub Desktop.
Save Jared-Prime/2371299 to your computer and use it in GitHub Desktop.
Olympic Tryouts - basic data validation
// Codeacademy.com project, "Olympic Tryouts"
// find the runner's average time
function calculateAverage(runnerTimes) {
var runnerTotal = 0;
for(i=0;i<runnerTimes.length;i++){
runnerTotal += runnerTimes[i];
}
var averageTime = runnerTotal / runnerTimes.length;
return averageTime;
}
// determine if runner is qualified to compete
var isQualified = function (runner) {
// Assign the variable averageTime
var averageTime = calculateAverage(runner);
if ( averageTime >= 11.5 ) {
// Times greater than or equal to 11.5 are too slow
console.log("Close, but you didn't make the cut.");
} else if ( averageTime < 11.5 ) {
// An average time of less than 11.5 can join the team
console.log("Welcome to the team, speedy!");
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment