Created
December 30, 2012 19:20
-
-
Save kmandreza/4414495 to your computer and use it in GitHub Desktop.
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'. For example, # How studious!
get_grade([100, 100, 100]) # => 'A'
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
def get_grade(test_scores) | |
x = test_scores.inject{|sum,x| sum + x } #sum of all test scores | |
y = x/test_scores.length #divide by number of test scores | |
if y >= 90 | |
return "A" | |
elsif y >=80 | |
return "B" | |
elsif y>= 70 | |
return "C" | |
elsif y>=60 | |
return "D" | |
elsif y <60 | |
return "F" | |
end | |
end | |
test_scores = [70, 65, 99, 83] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment