Ad

not immediately clear but its an alternative... :-D

Code
Diff
  • function getGrade (s1, s2, s3) { 
      const pos = (function rank(avg, grade, i) {
        if (avg / grade > 1 || i > 4) return i
        
        return rank(avg, grade-10, ++i)
      })((s1+s2+s3)/3, 90, 0)
      
      return String.fromCharCode(65 + pos)
    }
    • function getGrade (s1, s2, s3) {
    • let avg = (s1 + s2 + s3) / 3;
    • if (avg >= 90) {
    • return "A"
    • }
    • else if (avg >= 80) {
    • return "B"
    • }
    • else if (avg >= 70) {
    • return "C"
    • }
    • else if (avg >= 60) {
    • return "D"
    • }
    • else {return "F"}
    • function getGrade (s1, s2, s3) {
    • const pos = (function rank(avg, grade, i) {
    • if (avg / grade > 1 || i > 4) return i
    • return rank(avg, grade-10, ++i)
    • })((s1+s2+s3)/3, 90, 0)
    • return String.fromCharCode(65 + pos)
    • }