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
Input
95
Output
A
Input
82
Output
B
Input
59
Output
F
Hint
- Check the highest band first with an if / else if chain.
- 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.