getGrade

Easy · Conditionals · 5 test cases

Write a function that returns a letter grade (A, B, C, D, F) for a given numerical score. Use the standard grading scale: 90-100 is A, 80-89 is B, 70-79 is C, 60-69 is D, and below 60 is F.

Examples

getGrade(95) → 'A'
getGrade(82) → 'B'
getGrade(59) → 'F'

Starter code

function getGrade(score) {

}

Complexity of the optimal solution

Time O(1), space O(1). The function uses a series of if statements. In the worst case, it will perform 4 comparisons. This is a constant number of operations, making the complexity O(1).

Solve getGrade in the browser