Created
April 12, 2012 21:55
-
-
Save Jared-Prime/2371299 to your computer and use it in GitHub Desktop.
Olympic Tryouts - basic data validation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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