Student Grade
Programming Basics · JavaScript
TASK
Problem
Given score 0..100, print `5` for 90..100, `4` for 75..89, `3` for 60..74, and `2` otherwise.
EXAMPLE
Example
83
4
LIMITS
Constraints
0 ≤ score ≤ 100
LEARN
Theory for this problem
+
### Student Grade
JavaScript arithmetic works with numeric values stored in variables. A clear solution reads the needed values, computes the formula with `+`, `-`, `*`, `/` or `**`, and prints only the final result.
NEED HELP?
Hints
+
['Write the formula using named intermediate values if it contains more than one operation.', 'Separate input parsing, result computation, and output into distinct steps so errors are easier to spot.']
ANSWER
Solution
+
const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trimEnd();
let s = Number(input);
if (s >= 90) {
console.log(5);
} else {
if (s >= 75) {
console.log(4);
} else {
if (s >= 60) {
console.log(3);
} else {
console.log(2);
}
}
}