Delivery Availability
Programming Basics · JavaScript
TASK
Problem
Given distance in km and weight in kg. Delivery is available if distance≤30 and weight≤20.
EXAMPLE
Example
12 5
AVAILABLE
LIMITS
Constraints
distance ≥ 0; weight ≥ 0
LEARN
Theory for this problem
+
### Delivery Availability
`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.', 'Check values exactly on the condition boundary: `=`, `<`, and `>` must match the statement without an off-by-one shift.']
ANSWER
Solution
+
const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trimEnd();
let [d, w] = input.trim().split(/\s+/).filter(Boolean).map(Number);
if ((d <= 30) && (w <= 20)) {
console.log("AVAILABLE");
} else {
console.log("UNAVAILABLE");
}