ruby on rails - Calculate letter grade using a series of grades -


noob ruby here. working through exercises , have hit wall.

exercise: calculate letter grade of series of grades

create method get_grade accepts array of test scores. each score in array should between 0 , 100, 100 max score.

compute average score , return letter grade string, i.e., 'a', 'b', 'c', 'd', 'e', or 'f'.

i keep returning error:

avg.rb:1: syntax error, unexpected tlbrack, expecting ')' def get_grade([100,90,80])                ^ avg.rb:1: syntax error, unexpected ')', expecting $end 

here's have far. i'd stick methods below or .join i'm trying work methods we're learning in class. sum, inject, etc won't helpful. , apologize in advance specificity of request :) i'm sure there's way better way way less code, i'm trying learn way start.

    def get_grade([100,90,80])       get_grade = (array[0] + array[1] + array[2]).to_i / array.length.to_i     case get_grade       when 90..100       "a"       when 80..90        "b"       when 70..80        "c"       when 60..70        "d"       when 0..60        "f"       else      "error"       end     end      puts get_grade([100,90,80]) 

you can't randomly dump array literal [100,90,80] parameter list of function definition. judging function body, think meant accept single parameter array:

def get_grade(array)   grade = (array[0].to_i + array[1].to_i + array[2].to_i) / array.length   case grade     # unchanged   end end 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -