Best Score
Programming Basics · JavaScript
TASK
Problem
Given scores from three attempts, print the best score.
EXAMPLE
Example
72 91 88
91
LIMITS
Constraints
All numeric input values fit in JavaScript `Number`.
LEARN
Theory for this problem
+
### Best Score
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 [a, b, c] = input.trim().split(/\s+/).filter(Boolean).map(Number);
let best = a;
if (b > best) {
best = b;
}
if (c > best) {
best = c;
}
console.log(best);