PROBLEM 79
Medium

Time of Day

Programming Basics · JavaScript

</>
STATUS Not solved

TASK

Problem

#79

Given hour `h` 0..23, print `NIGHT`, `MORNING`, `DAY`, or `EVENING`.

EXAMPLE

Example

Input
14
Output
DAY

LIMITS

Constraints

0 ≤ h ≤ 23
📖
LEARN Theory for this problem
+

### Time of Day

`if / else if / else` chooses a branch from boolean conditions. Comparisons such as `<`, `>=`, `===` and logical operators `&&`, `||`, `!` combine the exact rules that decide which output is valid.

💡
NEED HELP? Hints
+

['Translate every case from the statement into a boolean condition before writing branches.', 'Match each input value type to the operation performed on it: JavaScript string and numeric behavior differ significantly.']

ANSWER Solution
+
const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trimEnd();
let h = Number(input);
if (h <= 5) {
    console.log("NIGHT");
} else {
    if (h <= 11) {
        console.log("MORNING");
    } else {
        if (h <= 17) {
            console.log("DAY");
        } else {
            console.log("EVENING");
        }
    }
}