Season
Programming Basics · JavaScript
TASK
Problem
Given month number, print `WINTER`, `SPRING`, `SUMMER`, or `AUTUMN`.
EXAMPLE
Example
9
AUTUMN
LIMITS
Constraints
1 ≤ month ≤ 12
LEARN
Theory for this problem
+
### Season
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 m = Number(input);
if (((m) === (12)) || (m <= 2)) {
console.log("WINTER");
} else {
if (m <= 5) {
console.log("SPRING");
} else {
if (m <= 8) {
console.log("SUMMER");
} else {
console.log("AUTUMN");
}
}
}