JavaScript bootcamp · Lab 05

Letter grade

easyIf Else10 minLesson: If Else

Read the question, write JavaScript on the right, then Run or Check.

QuestionHint and solution stay closed until you open them

Read a score from 0 to 100 and log its letter grade.

90+ is A, 80–89 B, 70–79 C, 60–69 D, and below 60 is F.

Input. One line: an integer 0–100.

Output. A single letter: A, B, C, D, or F.

Constraints

  • 0 ≤ score ≤ 100

Examples

Example 1
Input
95
Output
A
Example 2
Input
82
Output
B
Example 3 — Boundaries matter: 59 fails, 60 passes.
Input
59
Output
F
Hint
  1. Check the highest band first with an if / else if chain.
  2. A chained ternary works too: score >= 90 ? "A" : score >= 80 ? "B" : ...
Show correct code

Peek only after you have tried. You can still Check your own version.

const score = Number(readLine());
if (score >= 90) console.log("A");
else if (score >= 80) console.log("B");
else if (score >= 70) console.log("C");
else if (score >= 60) console.log("D");
else console.log("F");
main.jsconsole.log · readLine() · Ctrl + Enter
ResultIdle
Run to see output. Check grades the tests.