Skip to content

Instantly share code, notes, and snippets.

@nibanez80
Created February 8, 2013 05:52
Show Gist options
  • Save nibanez80/4736944 to your computer and use it in GitHub Desktop.
Save nibanez80/4736944 to your computer and use it in GitHub Desktop.
Exercise: Calculate the letter grade of a series of grades Create a method get_grade that accepts an Array of test scores. Each score in the array should be between 0 and 100, where 100 is the max score. Compute the average score and return the letter grade as a String, i.e., 'A', 'B', 'C', 'D', 'E', or 'F'.
def get_grade(array)
average = (array.inject(:+) / array.size)
if average >= 90; "A"
elsif average >= 80; "B"
elsif average >= 70; "C"
elsif average >= 60; "D"
else average >= 50; "F"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment