Turn a score into a letter grade

“Report card”, a White belt challenge from the CurlyScript Dojo. It uses what Grade 4: Making Decisions: if, else & Friends teaches, and 6 tests check your answer.

The challenge

Write letterGrade(score) that returns "A" for 80 and above, "B" for 70 to 79, "C" for 60 to 69, "D" for 50 to 59 and "F" below 50.

Try it

Write your answer below, then press Check my answer. Your code runs right here in your browser, and the tests tell you what works.

What the tests check

  • letterGrade(95) gives "A"
  • letterGrade(80) gives "A"
  • letterGrade(79) gives "B"
  • letterGrade(65) gives "C"
  • letterGrade(50) gives "D"
  • letterGrade(12) gives "F"

Hints

Stuck? Open one hint at a time. Try again after each one.

Hint 1

Use if / else if, checking the highest grade first.

Hint 2

Each return ends the function, so you don’t need && for ranges.

A solution

There’s always more than one right way. Read it, make sure you understand it, then try writing it yourself without looking.

Show one possible solution
Solution
function letterGrade(score) {
  if (score >= 80) return "A";
  if (score >= 70) return "B";
  if (score >= 60) return "C";
  if (score >= 50) return "D";
  return "F";
}

Learn what you need

This exercise uses what Grade 4: Making Decisions: if, else & Friends teaches. Read those notes first if any of it is new.

Practice makes it stick

CurlyScript is a free game that teaches JavaScript from zero: short lessons, an explanation after every answer, and Dojo challenges like this one.

Start learning