Day of Week
Programming Basics · JavaScript
TASK
Problem
Given weekday number 1..7, print the English day name.
EXAMPLE
Example
3
WEDNESDAY
LIMITS
Constraints
1 ≤ day ≤ 7
LEARN
Theory for this problem
+
### Day of Week
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.', 'Do not mix the loop counter with the accumulated answer; those variables serve different roles.']
ANSWER
Solution
+
const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trimEnd();
let d = Number(input);
if ((d) === (1)) {
console.log("MONDAY");
} else {
if ((d) === (2)) {
console.log("TUESDAY");
} else {
if ((d) === (3)) {
console.log("WEDNESDAY");
} else {
if ((d) === (4)) {
console.log("THURSDAY");
} else {
if ((d) === (5)) {
console.log("FRIDAY");
} else {
if ((d) === (6)) {
console.log("SATURDAY");
} else {
console.log("SUNDAY");
}
}
}
}
}
}