Even or Odd
Programming Basics · JavaScript
TASK
Problem
Given integer `n`, print `EVEN` if it is even, otherwise `ODD`.
EXAMPLE
Example
17
ODD
LIMITS
Constraints
All numeric input values fit in JavaScript `Number`.
LEARN
Theory for this problem
+
### Even or Odd
`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.', 'Order the checks so a more specific case is not swallowed by a broader condition.']
ANSWER
Solution
+
const fs = require('fs');
const n = Number(fs.readFileSync(0, 'utf8').trim());
const result = n % 2 === 0 ? 'EVEN' : 'ODD';
console.log(result);