Divisible by 3 and 5
Programming Basics · JavaScript
TASK
Problem
Print `YES` if `n` is divisible by both 3 and 5; otherwise print `NO`.
EXAMPLE
Example
30
YES
LIMITS
Constraints
All numeric input values fit in JavaScript `Number`.
LEARN
Theory for this problem
+
### Divisible by 3 and 5
`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 divisibleByBoth = n % 3 === 0 && n % 5 === 0;
console.log(divisibleByBoth ? 'YES' : 'NO');